7

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-1 hash values to identify the commit the change happened in?

Peter Mortensen
31.4k22 gold badges110 silver badges134 bronze badges
asked Jan 22, 2009 at 5:08
1
  • thats tight, i didnt know about svn ls for some reason, thanks Commented Jan 26, 2009 at 14:11

3 Answers 3

10

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 doesn't make any effort to reuse the results of previous searches. It is, however, a one-liner.

Peter Mortensen
31.4k22 gold badges110 silver badges134 bronze badges
answered Jan 22, 2009 at 14:08
Sign up to request clarification or add additional context in comments.

3 Comments

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
@koppor The full list is on the man page for git-log, under the PRETTY FORMATS section and the format:<string> listing: git-log man page
Man, I wish the man pages had actual examples of how to use all those lovely flags. :|
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
...
answered Jan 22, 2009 at 5:47

Comments

2

The question is: why do you need it? Currently Git lacks a 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 the nonlinear history, the notion who last changed a file is not unambiguous.

Peter Mortensen
31.4k22 gold badges110 silver badges134 bronze badges
answered Jan 26, 2009 at 13:41

4 Comments

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.
Oh and in this case, I knew the history was linear... all my changes stopped at least a month before anyone else touched it.
Wouldn't "git log -p --author=<name>" be a good alternate solution for this issue?
So you want to know all the files they changed. I think '--author=<name>' (or '--after=<date>', or <rev>.. 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.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.