English 中文(简体)
如何使“ git log -- stat -- <path 显示选中的 全部 * 文件 ” 生效?
原标题:How to make `git log --stat -- <path>` show *all* files in selected commits?
  • 时间:2012-05-22 23:51:00
  •  标签:
  • git

When I use a <path> argument with git log --stat to limit the log to commits modifying <path>, git lists <path> as the only modified file when displaying the selected commits. I would instead like to see all modified paths listed for each selected commit.

例如:

$ 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(-)

Note that the second git log, with the path argument a.txt, says "1 files changed", when in fact "2 files changed". I would like git to tell me that both a.txt and b.txt changed, even though I selected the commit based on the path a.txt.

更新: @ jacknagel 回答了我的问题, 但结果发现他的解决方案在我的真正使用案例中行不通。 在我的实际使用案例中, 我寻找所有对文件进行修改的人, 包括重命名, 在两个相关项目出现分歧的情况下。 我需要找出一个项目的修改意味着另一个项目的相应修改( 我需要做) 。 不幸的是, 当我同时尝试使用 < code>- full- diff < /code > 和 < code >- follow 时, 抱怨 < code > - full- diff 和 < code >- follown 。

所以,在我的真实情况下,我试图运行:

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.
问题回答

首先找到承诺代号, 然后管道到 alxargs (或 gnu parllel ), 将每个代号都输入 git 显示

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

在有电壳的窗户上,类似这样的东西应该有效(但我还没有测试过):

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




相关问题
git confusion - cloning a repo is returning a past version

Im having some confusion with my git usage. I cloned a repo from one comp to the other, and the new clone is the state of the original that was active some time ago. So its cloning a past version. ...

Appropriate strategy for tagging and hotfixing with git

I was wondering if the strategy I m using for tagging and hotfixing tags (which then I use for deploying rails applications) with git is appropriate. For tagging I just tag a commit of the master ...

Tips on upgrading CVS to git/hg?

We still use CVS, I use git and hg for my personal use though I m still a novice at both, but I realize they re much more modern and better, faster, distributed, etc. It s just everyone is so ...

Using Git in a TFS shop

Using Git at home has spoiled me - I now find using TFS at work to be a bit of a drag and want to explore the possibility of using Git locally and syncing somehow with TFS. I figure there are a few ...

热门标签