如何让 git log 显示文件名,如 svn log -v
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1230084/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to have git log show filenames like svn log -v
提问by jes5199
SVN's log has a "-v" mode that outputs filenames of files changed in each commit, like so:
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
Is there a quick way to get a list of changed files in each commit in git?
有没有一种快速的方法来获取 git 中每次提交中已更改文件的列表?
回答by CB Bailey
For full path names of changed files:
对于已更改文件的完整路径名:
git log --name-only
For full path names and status of changed files:
有关已更改文件的完整路径名和状态:
git log --name-status
For abbreviated pathnames and a diffstat of changed files:
对于缩写的路径名和已更改文件的 diffstat:
git log --stat
There's a lot more options, check out the docs.
还有更多选项,请查看文档。
回答by mipadi
NOTE:git whatchanged
is deprecated, use git log
instead
注意:已弃用,请改用git whatchanged
git log
New users are encouraged to use git-log[1]instead. The
whatchanged
command is essentially the same as git-log[1]but defaults to show the raw format diff output and to skip merges.The command is kept primarily for historical reasons; fingers of many people who learned Git long before
git log
was invented by reading Linux kernel mailing list are trained to type it.
鼓励新用户使用 git-log[1]代替。该
whatchanged
命令本质上与git-log[1]相同, 但默认显示原始格式差异输出并跳过合并。保留该命令主要是出于历史原因;许多很久以前
git log
通过阅读 Linux 内核邮件列表学习 Git 的人的手指都被训练来键入它。
You can use the command git whatchanged --stat
to get a list of files that changed in each commit (along with the commit message).
您可以使用该命令git whatchanged --stat
获取在每次提交中更改的文件列表(以及提交消息)。
References
参考
回答by ptc
git show
is also a great command.
git show
也是一个伟大的命令。
It's kind of like svn diff
, but you can pass it a commit guid and see that diff.
它有点像svn diff
,但是您可以将提交 guid 传递给它并查看差异。
回答by Hazok
If you want to get the file names only without the rest of the commit message you can use:
如果您只想获取文件名而没有提交消息的其余部分,您可以使用:
git log --name-only --pretty=format: <branch name>
This can then be extended to use the various options that contain the file name:
然后可以扩展它以使用包含文件名的各种选项:
git log --name-status --pretty=format: <branch name>
git log --stat --pretty=format: <branch name>
One thing to note when using this method is that there are some blank lines in the output that will have to be ignored. Using this can be useful if you'd like to see the files that have been changed on a local branch, but is not yet pushed to a remote branch and there is no guarantee the latest from the remote has already been pulled in. For example:
使用此方法时要注意的一件事是输出中有一些必须忽略的空行。如果您想查看本地分支上已更改但尚未推送到远程分支的文件,并且不能保证远程分支中的最新文件已经被拉入,则使用此功能会很有用。例如:
git log --name-only --pretty=format: my_local_branch --not origin/master
Would show all the files that have been changed on the local branch, but not yet merged to the master branch on the remote.
将显示本地分支上已更改但尚未合并到远程主分支的所有文件。
回答by xsor
I use this on a daily basis to show history with files that changed:
我每天都使用它来显示更改文件的历史记录:
git log --stat --pretty=short --graph
To keep it short, add an alias in your .gitconfig
by doing:
为了保持简短,请.gitconfig
通过执行以下操作在您的别名中添加别名:
git config --global alias.ls 'log --stat --pretty=short --graph'
回答by Sofia
I use this:
我用这个:
git log --name-status <branch>..<branch> | grep -E '^[A-Z]\b' | sort | uniq
which outputs a list of files only and their state (added, modified, deleted):
它只输出文件列表及其状态(添加、修改、删除):
A sites/api/branding/__init__.py
M sites/api/branding/wtv/mod.py
...
回答by nrz
git diff --stat HEAD^!
shows changed files and added/removed line counts for the last commit (HEAD
).
git diff --stat HEAD^!
显示最后一次提交 ( HEAD
)更改的文件和添加/删除的行数。
It seems to me that there is no single command to get concise output consisting only of filenames and added and removed line counts for several commits at once, so I created my own bash script for that:
在我看来,没有单一的命令可以同时获得仅包含文件名和添加和删除的多次提交的行数的简洁输出,因此我为此创建了自己的 bash 脚本:
#!/bin/bash
for ((i=0; i<=; i++))
do
sha1=`git log -1 --skip=$i --pretty=format:%H`
echo "HEAD~$i $sha1"
git diff --stat HEAD~$(($i+1)) HEAD~$i
done
To be called eg. ./changed_files 99
to get the changes in a concise form from HEAD
to HEAD~99
. Can be piped eg. to less
.
被称为例如。./changed_files 99
以简洁的形式获取从HEAD
到的更改HEAD~99
。可以管道,例如。到less
。
回答by Peter Suwara
I find the following is the ideal display for listing what files changed per commit in a concise format :
我发现以下是以简洁格式列出每次提交更改的文件的理想显示:
git log --pretty=oneline --graph --name-status
回答by JamesThomasMoon1979
A summary of answers with example output
带有示例输出的答案摘要
This is using a local repository with five simple commits.
这是使用具有五个简单提交的本地存储库。
? git log --name-only
commit ed080bc88b7bf0c5125e093a26549f3755f7ae74 (HEAD -> master)
Author: My Name <[email protected]>
Date: Mon Oct 21 15:46:04 2019 -0700
mv file4 to file5
file5
commit 5c4e8cfbe3554fe3d7d99b5ae4ba381fa1cdb328
Author: My Name <[email protected]>
Date: Mon Oct 21 15:36:32 2019 -0700
foo file1
really important to foo before the bar
file1
commit 1b6413400b5a6a96d062a7c13109e6325e081c85
Author: My Name <[email protected]>
Date: Mon Oct 21 15:34:37 2019 -0700
foobar file2, rm file3
file2
file3
commit e0dd02ce23977c782987a206236da5ab784543cc
Author: My Name <[email protected]>
Date: Mon Oct 21 15:33:05 2019 -0700
Add file4
file4
commit b58e85692f711d402bae4ca606d3d2262bb76cf1
Author: My Name <[email protected]>
Date: Mon Oct 21 15:32:41 2019 -0700
Added files
file1
file2
file3
? git log --name-status
commit ed080bc88b7bf0c5125e093a26549f3755f7ae74 (HEAD -> master)
Author: My Name <[email protected]>
Date: Mon Oct 21 15:46:04 2019 -0700
mv file4 to file5
R100 file4 file5
commit 5c4e8cfbe3554fe3d7d99b5ae4ba381fa1cdb328
Author: My Name <[email protected]>
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 <[email protected]>
Date: Mon Oct 21 15:34:37 2019 -0700
foobar file2, rm file3
M file2
D file3
commit e0dd02ce23977c782987a206236da5ab784543cc
Author: My Name <[email protected]>
Date: Mon Oct 21 15:33:05 2019 -0700
Add file4
A file4
commit b58e85692f711d402bae4ca606d3d2262bb76cf1
Author: My Name <[email protected]>
Date: Mon Oct 21 15:32:41 2019 -0700
Added files
A file1
A file2
A file3
? git log --stat
commit ed080bc88b7bf0c5125e093a26549f3755f7ae74 (HEAD -> master)
Author: My Name <[email protected]>
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
Date: Mon Oct 21 15:32:41 2019 -0700
Added files
file1 | 0
file2 | 0
file3 | 0
3 files changed, 0 insertions(+), 0 deletions(-)
? 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
? 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
? git diff-tree HEAD
ed080bc88b7bf0c5125e093a26549f3755f7ae74
:100644 000000 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0000000000000000000000000000000000000000 D file4
:000000 100644 0000000000000000000000000000000000000000 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 A file5
? git log --stat --pretty=short --graph
* commit ed080bc88b7bf0c5125e093a26549f3755f7ae74 (HEAD -> master)
| Author: My Name <[email protected]>
|
| mv file4 to file5
|
| file4 => file5 | 0
| 1 file changed, 0 insertions(+), 0 deletions(-)
|
* commit 5c4e8cfbe3554fe3d7d99b5ae4ba381fa1cdb328
| Author: My Name <[email protected]>
|
| foo file1
|
| file1 | 3 +++
| 1 file changed, 3 insertions(+)
|
* commit 1b6413400b5a6a96d062a7c13109e6325e081c85
| Author: My Name <[email protected]>
|
| foobar file2, rm file3
|
| file2 | 1 +
| file3 | 0
| 2 files changed, 1 insertion(+)
|
* commit e0dd02ce23977c782987a206236da5ab784543cc
| Author: My Name <[email protected]>
|
| Add file4
|
| file4 | 0
| 1 file changed, 0 insertions(+), 0 deletions(-)
|
* commit b58e85692f711d402bae4ca606d3d2262bb76cf1
Author: My Name <[email protected]>
Added files
file1 | 0
file2 | 0
file3 | 0
3 files changed, 0 insertions(+), 0 deletions(-)
? git log --name-only --pretty=format:
file5
file1
file2
file3
file4
file1
file2
file3
? git log --name-status --pretty=format:
R100 file4 file5
M file1
M file2
D file3
A file4
A file1
A file2
A file3
? git diff --stat 'HEAD^!'
file4 => file5 | 0
1 file changed, 0 insertions(+), 0 deletions(-)
? git show
commit ed080bc88b7bf0c5125e093a26549f3755f7ae74 (HEAD -> master)
Author: My Name <[email protected]>
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
Credits to @CB-Bailey @Peter-Suwara @Gaurav @Omer-Dagan @xsor @Hazok @nrz @ptc
感谢@CB-Bailey @Peter-Suwara @Gaurav @Omer-Dagan @xsor @Hazok @nrz @ptc
回答by Omer Dagan
Another useful command would be git diff-tree <hash>
where hash can be also a hash range (denoted by <old>..<new>
notation). An output example:
另一个有用的命令是git diff-tree <hash>
hash 也可以是一个散列范围(用<old>..<new>
符号表示)。输出示例:
$ git diff-tree HEAD
:040000 040000 8e09a be406 M myfile
The fields are:
这些字段是:
source mode, dest mode, source hash, dest hash, status, filename
源模式、目标模式、源哈希、目标哈希、状态、文件名
Statuses are the ones you would expect: D(deleted), A(added), M(modified) etc. See man page for full description.
状态是您期望的状态:D(已删除)、A(已添加)、M(已修改)等。有关完整说明,请参见手册页。