很好地在git log中显示文件重命名历史记录 [英] nicely display file rename history in git log
问题描述
git
命令 git log --format =' %H'--follow - foo.txt
会为您提供一系列触碰 foo.txt
,然后跨越重命名。
我想知道是否有 git
这将是这样的,我们可以在这里解释'%F'
是文件名的(实际上不存在的)占位符。
git log --format ='%H%F'--follow - foo.txt
我知道这可以用
> git log --format ='%H'--follow --numstat - foo.txt
但输出并不理想,因为它需要一些非平凡的解析;每个提交都分散在多行中,并且仍然需要解析文件重命名语法(bar.txt => foo.txt
)以查找您的'
您可以简化它,就像这样:
git log --format ='%H'--name-only --follow - README.md
这会给你类似的输出
621175c4998dfda8da
README.md
d0d6ef0a3d22269b96
README.md
这应该更容易解析。例如,你可以使用一个哨兵并像这样发布新行:
git log --format ='%H %% '--name-only --follow - README.md | sed':a; N; $!ba; s /%\\\
\\\
/ / g'
621175c4998dfda8da README.md
d0d6ef0a3d22269b96 这应该会给你散列和文件名在同一行上:
README.md
有关sed调用的信息,请参阅)?,它具有我基于该位的答案开。
The git
command
git log --format='%H' --follow -- foo.txt
will give you the series of commits that touch foo.txt
, following it across renames.
I'm wondering if there's a git log
command that will also print the corresponding historical file name beside each commit.
It would be something like this, where we can interpret '%F'
to be the (actually non-existent) placeholder for filename.
git log --format='%H %F' --follow -- foo.txt
I know this could be accomplished with
git log --format='%H' --follow --numstat -- foo.txt
but the output is not ideal since it requires some non-trivial parsing; each commit is strewn across multiple lines, and you'll still need to parse the file rename syntax ("bar.txt => foo.txt"
) to find what you're looking for.
You can simplify it a little bit like this:
git log --format='%H' --name-only --follow -- README.md
which will give you output kind of like this
621175c4998dfda8da
README.md
d0d6ef0a3d22269b96
README.md
which should be a little easier to parse. For instance you can use a sentinel and sed out the newlines like this:
git log --format='%H%%' --name-only --follow -- README.md | sed ':a;N;$!ba;s/%\n\n/ /g'
which should give you the hash and the filename on the same line:
621175c4998dfda8da README.md
d0d6ef0a3d22269b96 README.md
For info on the sed invocation, see How can I replace a newline (\n) using sed? which has the answer I based that bit on.
这篇关于很好地在git log中显示文件重命名历史记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!