6

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?

Otto
  • 18,761
  • 15
  • 56
  • 62

3 Answers3

9

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.

CB Bailey
  • 755,051
  • 104
  • 632
  • 656
  • Also added --no-pager and another echo to get a new line. for a in $(ls); do git --no-pager log --pretty=format:"%h%x09%an%x09%ad%x09$a" -1 -- "$a"; echo "" ; done – Otto Jan 22 '09 at 15:32
  • 3
    @koppor The full list is on the man page for git-log, under the PRETTY FORMATS section and the format: listing: [git-log man page](https://www.kernel.org/pub/software/scm/git/docs/git-log.html) – Nathan Weir Jul 08 '13 at 19:54
7

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
...
dylanfm
  • 6,292
  • 5
  • 28
  • 29
2

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.

Jakub Narębski
  • 309,089
  • 65
  • 217
  • 230
  • I only needed it in one particular, weird case. I was removing kruft from previous versions of a website after two other people re-designed it. Anything that was added by me was from the old site, anything from them was new. Day to day, you're right, I wouldn't need it. – Otto Jan 26 '09 at 17:38
  • Oh and in this case, I knew the history was linear... all my changes stopped at least a month before anyone else touched it. – Otto Jan 26 '09 at 17:41
  • Wouldn't "git log -p --author=" be a good alternate solution for this issue? – Jakub Narębski Jan 27 '09 at 10:28
  • So you want to know all the files they changed. I think '--author=' (or '--after=', or .. specifier) combined with '--names-only' and appropriate '--pretty=format=...' option, and sort and uniq, can be used to generate list of all files changed by them. – Jakub Narębski Jan 27 '09 at 12:54