How to have git log show filenames like svn log -v

2019-01-05 06:36发布

SVN's log has a "-v" mode that outputs filenames of files changed in each commit, like so:

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?

标签: svn git logging
7条回答
虎瘦雄心在
2楼-- · 2019-01-05 06:58

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:

git config --global alias.ls 'log --stat --pretty=short --graph'
查看更多
三岁会撩人
3楼-- · 2019-01-05 07:15

git show is also a great command.

It's kind of like svn diff, but you can pass it a commit guid and see that diff.

查看更多
smile是对你的礼貌
4楼-- · 2019-01-05 07:17

NOTE: git whatchanged is deprecated, use git log instead

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.


You can use the command git whatchanged --stat to get a list of files that changed in each commit (along with the commit message).

References

查看更多
孤傲高冷的网名
5楼-- · 2019-01-05 07:19

git diff --stat HEAD^! shows changed files and added/removed line counts for the last commit (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:

#!/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

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.

查看更多
相关推荐>>
6楼-- · 2019-01-05 07:22

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:

git log --stat

There's a lot more options, check out the docs.

查看更多
Ridiculous、
7楼-- · 2019-01-05 07:23

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.

查看更多
登录 后发表回答