git log output like svn ls -v

有些话、适合烂在心里 提交于 2019-12-30 06:34:28

问题


Is there a way to make git give me output like svn ls -v does. Basically a list of each file and who last edited that file? Like this:

filea.txt     Someone Else
fileb.txt     Another Person

Maybe even with the SHA to identify the commit the change happened in?


回答1:


It's not a very natural question to ask in git, but you can probably achieve something like what you want with something like this.

for a in $(ls); do git log --pretty=format:"%h%x09%an%x09%ad%x09$a" -1 -- "$a"; done

This goes through each file in the current directory and performs a git log on it to find the last commit to have affected it.

It's not very efficient, as it searches the git history for each file and makes no effort to reuse the results of previous searches. It is, however, a one-liner.




回答2:


You want to play around with git log and its pretty formats. Here's an example that doesn't completely address what you want, but should get you on the way:

git log --pretty=format:"%h: %s -- %an"

Prints:

...
58a2e46: Added readme for github. -- DylanFM
...



回答3:


The question is: why do you need it? Currently git lacks single command that would do "svn ls -v" equivalent, and you would have to do a bit of scripting: the "git log -1 -- $filename" idea is, I think, the simplest solution (in term of number of lines of script to write); if it would, it probably will be as "git blame ".

But I guess that there is alternate way to solve your issue that you used "svn ls -v" to solve.

Please also remember that with nonlinear history the notion who last changed file is not unambiguous.



来源:https://stackoverflow.com/questions/468106/git-log-output-like-svn-ls-v

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!