请教magit staged changes时,如何只显示文件名,不插入文件内容?

如题,在windows下,magit初始化仓库时,会把文件内容也插入到status buffer,文件多时(3000+),太卡了,当前buffer几乎无法查看搜索。

首次提交我只想看下文件名,不想看内容,故有此需求。

magit-status-sections-hook 看看这个hook

临时用下(remove-hook 'magit-status-sections-hook #'magit-insert-staged-changes)或许可以

win下面IO太慢进程开销大,可能问题不在于你说的那个,建议参考下这个blog Speeding up magit - Jake McCrary

好像不能删除,删了后只有一行“In the beginning there was darkness”。

这个是profile report,不是太明白。

- command-execute                                                4681  99%
 - call-interactively                                            4681  99%
  - funcall-interactively                                        4681  99%
   - magit-refresh                                               4681  99%
    - magit-refresh-buffer                                       4679  99%
     - apply                                                     4671  99%
      - magit-status-refresh-buffer                              4671  99%
       - magit-run-section-hook                                  4670  99%
        - apply                                                  4670  99%
         - magit-insert-staged-changes                           4658  98%
          - magit--insert-diff                                   4656  98%
           - magit-git-wash                                      4656  98%
            - magit-diff-wash-diffs                              4579  97%
             - magit-wash-sequence                               4579  97%
              - #<compiled 0x9f032f1299>                         4579  97%
               - apply                                           4579  97%
                - magit-diff-wash-diff                           4572  97%
                 - magit-diff-insert-file-section                2206  46%
                  + magit-wash-sequence                          1195  25%
                  + magit-get-section                             541  11%
                  + magit-insert-heading                           16   0%
                  + run-hook-with-args-until-success                  8   0%
                  + magit-file-section                              5   0%
                  + eieio-oref                                      3   0%
                  + eieio-oset                                      2   0%
                  + magit-section-ident                             1   0%
                    class-p                                         1   0%
                    symbol-overlay-refresh                          1   0%
                 + magit-delete-line                               50   1%
                 + cl-member-if                                     2   0%
                 + derived-mode-p                                   2   0%
            + magit-git-insert                                     77   1%
          + magit-bare-repo-p                                       1   0%
            magit-insert-child-count                                1   0%
         + magit-todos--insert-todos                                3   0%
         + magit-insert-unpushed-to-pushremote                      2   0%
         + magit-insert-status-headers                              1   0%
         + magit-insert-merge-log                                   1   0%
         + magit-insert-untracked-files                             1   0%
           magit-insert-unstaged-changes                            1   0%
         + magit-insert-modules                                     1   0%
         + magit-insert-unpushed-to-upstream-or-recent                  1   0%
       + magit-git-exit-code                                        1   0%
    + magit-run-hook-with-benchmark                                 2   0%

80多秒才完成refresh

Refreshing buffer ‘magit: cms’...
  magit-insert-staged-changes                        80.302179 !!
  magit-insert-status-headers                        0.143681 !!
  magit-insert-merge-log                             0.1288 !!
  magit-insert-rebase-sequence                       0.000975 
  magit-insert-am-sequence                           0.000564 
  magit-insert-sequencer-sequence                    0.000842 
  magit-insert-bisect-output                         0.000482 
  magit-insert-bisect-rest                           0.000159 
  magit-insert-bisect-log                            0.000152 
  magit-insert-untracked-files                       0.30641 !!
  magit-insert-unstaged-changes                      0.140303 !!
  magit-insert-stashes                               0.123835 !!
  magit-insert-modules                               0.156518 !!
  magit-insert-unpushed-to-pushremote                0.137505 !!
  magit-insert-unpushed-to-upstream-or-recent        0.401468 !!
  magit-insert-unpulled-from-pushremote              9e-06 
  magit-insert-unpulled-from-upstream                1.3e-05 
  magit-todos--insert-todos                          0.21223 !!
Refreshing buffer ‘magit: cms’...done (82.670s)
Running magit-post-refresh-hook...done (0.145s)
Refreshing magit...done (83.113s, cached 22/41 (54%))

应该就是magit-insert-staged-changes这个函数运行时间太长引起的,它负责往magit status 那个buffer里面写stage信息,源码是:

(defun magit-insert-staged-changes ()
  "Insert section showing staged changes."
  ;; Avoid listing all files as deleted when visiting a bare repo.
  (unless (magit-bare-repo-p)
    (magit-insert-section (staged)
      (magit-insert-heading "Staged changes:")
      (magit--insert-diff
        "diff" "--cached" magit-buffer-diff-args "--no-prefix"
        "--" magit-buffer-diff-files))))

写个advice,把magit--insert-diff去掉或者用一个条件语句自定义一下只在需要的时候执行这个,应该就能做到只显示heading了

我是想在首次提交时,检查一遍所有文件。不用去看内容。现在这个函数是把所有staged文件的内容都插入进去,各种操作都慢得不行。

可以考虑下直接在终端操作,或者用eshell,回到命令行,毕竟这种是少数情况。

谢谢提醒,思维受限了。呵呵

对了,甚至都不用开终端或者 eshell ,直接在 minibuffer 操作(M-x shell-command,默认快捷键是 M-!),然后输入 git status 命令或者 git commit -m "xxx" 提交就行了。

哈哈,多谢提醒。windows命令行和eshell都中文乱码。M-!竟然不乱,真是奇怪。windows下真是够折腾。