如何让git log显示文件名,如svn log -v

jes*_*199 925 svn git logging

SVN的日志有一个"-v"模式,输出每次提交中更改的文件的文件名,如下所示:

jes5199$ svn log -v
------------------------------------------------------------------------
r1 |   jes5199 | 2007-01-03 14:39:41 -0800 (Wed, 03 Jan 2007) | 1 line
Changed paths:
   A /AUTHORS
   A /COPYING
   A /ChangeLog
   A /EVOLUTION
   A /INSTALL
   A /MacOSX

有没有一种快速的方法来获取git中每个提交中的已更改文件列表?

CB *_*ley 1438

对于已更改文件的完整路径名:

git log --name-only
Run Code Online (Sandbox Code Playgroud)

对于完整路径名和已更改文件的状态:

git log --name-status
Run Code Online (Sandbox Code Playgroud)

对于缩写的路径名和已更改文件的diffstat:

git log --stat
Run Code Online (Sandbox Code Playgroud)

还有更多选项,请查看文档.

  • `git log --name-only --oneline`也很漂亮 - 提交一条彩色线,每行一个文件.http://stackoverflow.com/a/14227496/1995714 (25认同)
  • 我用`git log --numstat`.有关更多选项,请参阅`git help log`. (15认同)
  • 使用git 2.7.3,我不得不使用`git log --name-status --find-renames`来显示重命名的文件而不是添加+删除. (3认同)
  • @ma11hew28 谢谢。自 git 2.22.00 起,`--numstat` 位于该手册页的第 946 行。这比大多数人需要的选择要多“很多”。 (3认同)
  • 请注意,“--stat”缩写了长路径;宽度是可配置的,但包裹的直方图更难以阅读。其他格式(如“--numstat”)始终打印完整路径。 (2认同)

mip*_*adi 139

注意:已弃用,请改用 git whatchangedgit log

鼓励新用户改用 git-log [1].该 whatchanged命令与git-log [1]基本相同, 但默认显示原始格式diff输出并跳过合并.

该命令主要是出于历史原因; 很久以前git log通过阅读Linux内核邮件列表发明了很多人学习Git的手指都经过培训才能打字.


您可以使用该命令git whatchanged --stat获取每次提交中更改的文件列表(以及提交消息).

参考


小智 47

git show 也是一个伟大的命令.

它有点像svn diff,但你可以传递一个提交guid并看到差异.

  • 它不是提交的 _GUID_ 而是其 SHA1 哈希值。 (3认同)

Haz*_*zok 43

如果您只想获取文件名而不使用其余的提交消息,则可以使用:

git log --name-only --pretty=format: <branch name>
Run Code Online (Sandbox Code Playgroud)

然后可以将其扩展为使用包含文件名的各种选项:

git log --name-status --pretty=format: <branch name>

git log --stat --pretty=format: <branch name>
Run Code Online (Sandbox Code Playgroud)

使用此方法时需要注意的一点是输出中有一些空白行必须被忽略.如果您希望查看已在本地分支上更改但尚未推送到远程分支的文件并且无法保证已从中拉入最新的远程文件,则使用此选项非常有用.例如:

git log --name-only --pretty=format: my_local_branch --not origin/master
Run Code Online (Sandbox Code Playgroud)

将显示已在本地分支上更改但尚未合并到远程主分支的所有文件.


xso*_*sor 38

我每天都使用它来显示更改过的文件的历史记录:

git log --stat --pretty=short --graph
Run Code Online (Sandbox Code Playgroud)

为了简短起见,请在您.gitconfig的操作中添加一个别名:

git config --global alias.ls 'log --stat --pretty=short --graph'
Run Code Online (Sandbox Code Playgroud)

  • 我的非常接近,git log --pretty=oneline --graph --name-status。我发现它更简洁,只显示已更改的文件列表。 (2认同)

Ami*_*esh 32

这个简短的命令对于列出每次提交更改的所有文件非常有帮助。

git log --name-only --oneline
Run Code Online (Sandbox Code Playgroud)

--仅名称

仅显示已更改文件的名称。文件名通常采用 UTF-8 编码。有关更多信息,请参阅 git-log 1手册页中有关编码的讨论。

- 一条线

This is a shorthand for "--pretty=oneline --abbrev-commit" used together.
Run Code Online (Sandbox Code Playgroud)

输出 输出


Sof*_*fia 15

我用这个:

git log --name-status <branch>..<branch> | grep -E '^[A-Z]\b' | sort | uniq
Run Code Online (Sandbox Code Playgroud)

它仅输出文件列表及其状态(添加,修改,删除):

A   sites/api/branding/__init__.py
M   sites/api/branding/wtv/mod.py
...
Run Code Online (Sandbox Code Playgroud)


Pet*_*ara 8

我发现以下是以简洁的格式列出每次提交更改的文件的理想显示:

git log --pretty=oneline --graph --name-status
Run Code Online (Sandbox Code Playgroud)


nrz*_*nrz 7

git diff --stat HEAD^!显示最后一次commit(HEAD)的已更改文件和添加/删除的行计数.

在我看来,没有一个命令可以获得简洁的输出,只包含文件名,并且一次添加和删除几次提交的行数,所以我为此创建了自己的bash脚本:

#!/bin/bash
for ((i=0; i<=$1; i++))
do
    sha1=`git log -1 --skip=$i --pretty=format:%H`
    echo "HEAD~$i $sha1"
    git diff --stat HEAD~$(($i+1)) HEAD~$i 
done
Run Code Online (Sandbox Code Playgroud)

被称为例如../changed_files 99从获得一个简洁的形式的变化HEADHEAD~99.可以用管道输送.到less.


Jam*_*979 6

带有示例输出的答案摘要

这是使用具有五个简单提交的本地存储库。

? git log --name-only
commit ed080bc88b7bf0c5125e093a26549f3755f7ae74 (HEAD -> master)
Author: My Name <user@email.com>
Date:   Mon Oct 21 15:46:04 2019 -0700

    mv file4 to file5

file5

commit 5c4e8cfbe3554fe3d7d99b5ae4ba381fa1cdb328
Author: My Name <user@email.com>
Date:   Mon Oct 21 15:36:32 2019 -0700

    foo file1

    really important to foo before the bar

file1

commit 1b6413400b5a6a96d062a7c13109e6325e081c85
Author: My Name <user@email.com>
Date:   Mon Oct 21 15:34:37 2019 -0700

    foobar file2, rm file3

file2
file3

commit e0dd02ce23977c782987a206236da5ab784543cc
Author: My Name <user@email.com>
Date:   Mon Oct 21 15:33:05 2019 -0700

    Add file4

file4

commit b58e85692f711d402bae4ca606d3d2262bb76cf1
Author: My Name <user@email.com>
Date:   Mon Oct 21 15:32:41 2019 -0700

    Added files

file1
file2
file3
Run Code Online (Sandbox Code Playgroud)


? git log --name-status
commit ed080bc88b7bf0c5125e093a26549f3755f7ae74 (HEAD -> master)
Author: My Name <user@email.com>
Date:   Mon Oct 21 15:46:04 2019 -0700

    mv file4 to file5

R100    file4   file5

commit 5c4e8cfbe3554fe3d7d99b5ae4ba381fa1cdb328
Author: My Name <user@email.com>
Date:   Mon Oct 21 15:36:32 2019 -0700

    foo file1

    really important to foo before the bar

M       file1

commit 1b6413400b5a6a96d062a7c13109e6325e081c85
Author: My Name <user@email.com>
Date:   Mon Oct 21 15:34:37 2019 -0700

    foobar file2, rm file3

M       file2
D       file3

commit e0dd02ce23977c782987a206236da5ab784543cc
Author: My Name <user@email.com>
Date:   Mon Oct 21 15:33:05 2019 -0700

    Add file4

A       file4

commit b58e85692f711d402bae4ca606d3d2262bb76cf1
Author: My Name <user@email.com>
Date:   Mon Oct 21 15:32:41 2019 -0700

    Added files

A       file1
A       file2
A       file3
Run Code Online (Sandbox Code Playgroud)


? git log --stat
commit ed080bc88b7bf0c5125e093a26549f3755f7ae74 (HEAD -> master)
Author: My Name <user@email.com>
Date:   Mon Oct 21 15:46:04 2019 -0700

    mv file4 to file5

 file4 => file5 | 0
 1 file changed, 0 insertions(+), 0 deletions(-)

commit 5c4e8cfbe3554fe3d7d99b5ae4ba381fa1cdb328
Author: My Name <user@email.com>
Date:   Mon Oct 21 15:36:32 2019 -0700

    foo file1

    really important to foo before the bar

 file1 | 3 +++
 1 file changed, 3 insertions(+)

commit 1b6413400b5a6a96d062a7c13109e6325e081c85
Author: My Name <user@email.com>
Date:   Mon Oct 21 15:34:37 2019 -0700

    foobar file2, rm file3

 file2 | 1 +
 file3 | 0
 2 files changed, 1 insertion(+)

commit e0dd02ce23977c782987a206236da5ab784543cc
Author: My Name <user@email.com>
Date:   Mon Oct 21 15:33:05 2019 -0700

    Add file4

 file4 | 0
 1 file changed, 0 insertions(+), 0 deletions(-)

commit b58e85692f711d402bae4ca606d3d2262bb76cf1
Author: My Name <user@email.com>
Date:   Mon Oct 21 15:32:41 2019 -0700

    Added files

 file1 | 0
 file2 | 0
 file3 | 0
 3 files changed, 0 insertions(+), 0 deletions(-)
Run Code Online (Sandbox Code Playgroud)


? git log --name-only --oneline
ed080bc (HEAD -> master) mv file4 to file5
file5
5c4e8cf foo file1
file1
1b64134 foobar file2, rm file3
file2
file3
e0dd02c Add file4
file4
b58e856 Added files
file1
file2
file3
Run Code Online (Sandbox Code Playgroud)


? git log --pretty=oneline --graph --name-status
* ed080bc88b7bf0c5125e093a26549f3755f7ae74 (HEAD -> master) mv file4 to file5
| R100  file4   file5
* 5c4e8cfbe3554fe3d7d99b5ae4ba381fa1cdb328 foo file1
| M     file1
* 1b6413400b5a6a96d062a7c13109e6325e081c85 foobar file2, rm file3
| M     file2
| D     file3
* e0dd02ce23977c782987a206236da5ab784543cc Add file4
| A     file4
* b58e85692f711d402bae4ca606d3d2262bb76cf1 Added files
  A     file1
  A     file2
  A     file3
Run Code Online (Sandbox Code Playgroud)


? git diff-tree HEAD
ed080bc88b7bf0c5125e093a26549f3755f7ae74
:100644 000000 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0000000000000000000000000000000000000000 D  file4
:000000 100644 0000000000000000000000000000000000000000 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 A  file5
Run Code Online (Sandbox Code Playgroud)


? git log --stat --pretty=short --graph
* commit ed080bc88b7bf0c5125e093a26549f3755f7ae74 (HEAD -> master)
| Author: My Name <user@email.com>
| 
|     mv file4 to file5
| 
|  file4 => file5 | 0
|  1 file changed, 0 insertions(+), 0 deletions(-)
| 
* commit 5c4e8cfbe3554fe3d7d99b5ae4ba381fa1cdb328
| Author: My Name <user@email.com>
| 
|     foo file1
| 
|  file1 | 3 +++
|  1 file changed, 3 insertions(+)
| 
* commit 1b6413400b5a6a96d062a7c13109e6325e081c85
| Author: My Name <user@email.com>
| 
|     foobar file2, rm file3
| 
|  file2 | 1 +
|  file3 | 0
|  2 files changed, 1 insertion(+)
| 
* commit e0dd02ce23977c782987a206236da5ab784543cc
| Author: My Name <user@email.com>
| 
|     Add file4
| 
|  file4 | 0
|  1 file changed, 0 insertions(+), 0 deletions(-)
| 
* commit b58e85692f711d402bae4ca606d3d2262bb76cf1
  Author: My Name <user@email.com>

      Added files

   file1 | 0
   file2 | 0
   file3 | 0
   3 files changed, 0 insertions(+), 0 deletions(-)
Run Code Online (Sandbox Code Playgroud)


? git log --name-only --pretty=format:
file5

file1

file2
file3

file4

file1
file2
file3
Run Code Online (Sandbox Code Playgroud)


? git log --name-status --pretty=format:
R100    file4   file5

M       file1

M       file2
D       file3

A       file4

A       file1
A       file2
A       file3
Run Code Online (Sandbox Code Playgroud)


? git diff --stat 'HEAD^!'
 file4 => file5 | 0
 1 file changed, 0 insertions(+), 0 deletions(-)
Run Code Online (Sandbox Code Playgroud)


? git show
commit ed080bc88b7bf0c5125e093a26549f3755f7ae74 (HEAD -> master)
Author: My Name <user@email.com>
Date:   Mon Oct 21 15:46:04 2019 -0700

    mv file4 to file5

diff --git a/file4 b/file5
similarity index 100%
rename from file4
rename to file5
Run Code Online (Sandbox Code Playgroud)


感谢@CB-Bailey @Peter-Suwara @Gaurav @Omer-Dagan @xsor @Hazok @nrz @ptc


Man*_*noj 6

我在用:

git diff-tree -v --name-status -r <commit-id>
Run Code Online (Sandbox Code Playgroud)

它显示与 svn log -v 非常相似的输出