簡體   English   中英

如何制作`git log --stat - <path> `show * all *文件在選定的提交中?

[英]How to make `git log --stat — <path>` show *all* files in selected commits?

當我使用帶有git log --stat<path>參數來限制日志提交修改<path> ,git將<path>列為顯示所選提交時唯一修改過的文件。 我希望看到為每個選定的提交列出的所有修改路徑。

例如:

$ echo test > a.txt
$ echo test > b.txt
$ git add a.txt b.txt
$ git commit -m test
 [...]
 2 files changed, 2 insertions(+), 0 deletions(-)
 [...]
$ git log -n1 --stat
 [...]

 a.txt |    1 +
 b.txt |    1 +
 2 files changed, 2 insertions(+), 0 deletions(-)
$ git log -n1 --stat -- a.txt
 [...]

 a.txt |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

請注意,第二個git log ,其路徑參數為a.txt ,表示“1個文件已更改”,實際上“2個文件已更改”。 我想git告訴我a.txtb.txt改變了,即使我根據路徑a.txt選擇了提交。

更新:@jacknagel回答了我的問題,但事實證明他的解決方案在我的實際用例中不起作用。 在我的實際用例中,我正在尋找修改文件的所有提交,包括重命名,在兩個相關項目分歧的情況下。 我需要弄清楚一個項目中的哪些變化意味着在另一個項目中有相應的變化(我需要做出)。 不幸的是,當我嘗試同時使用--full-diff--follow時, git抱怨。

所以,在我的實際情況中,我正試圖運行:

git log --stat --follow -- a.txt

在這種情況下有效的解決方案是:

git log --format='%H' --follow -- a.txt | xargs git show --stat -C

您可以使用--full-diff選項獲得此行為:

   --full-diff
       Without this flag, "git log -p <path>..." shows commits that touch
       the specified paths, and diffs about the same specified paths. With
       this, the full diff is shown for commits that touch the specified
       paths; this means that "<path>..." limits only commits, and doesn't
       limit diff for those commits.

       Note that this affects all diff-based output types, e.g. those
       produced by --stat etc.

首先找到提交ID,然后將它們傳遞給xargs (或gnu parallel )以將每個id提供給git show

git log --format='%H' --follow -- a.txt | xargs git show --stat -C

在使用PowerShell的Windows上,這樣的東西應該可以工作(但我還沒有測試過它......):

git log --format='%H' --follow -- a.txt | ForEach-Object { git show --stat -C $_ }

您如何期望命令以不同於預期的方式運行? 當你給出文件名時,你告訴git單獨獲取該文件的詳細信息。 如果您希望它顯示兩個文件,請使用該命令

git log -n1 --stat .

要么

git log -n1 --stat a.txt b.txt

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM