1

Is it possible to git blame on a files/folders level instead of the "line by line"-level?

The command git blame usually shows the last commit affecting each line in a given document, but what I'm wondering is whether you get a list of what was the last commit affecting each file. Judging from the options it is not possible to do using git blame but is there some other command that might do something similar?

EDIT: Ideally I'd like to get a list with the file names where for each file we also get the commit hash, the name of the person who edited the file last as well as the date.

Romain Valeri
  • 19,645
  • 3
  • 36
  • 61
flawr
  • 10,814
  • 3
  • 41
  • 71

1 Answers1

1

Not sure it suits your needs but

git log -1 --pretty=format:"%an" -- path/to/file

would output the name of the last person having modified the file (or directory).

Edit after comments :

To loop over files of a directory, in a bash context, use xargs :

git ls-files path/to/directory/ | xargs -n 1 git log -1 --pretty=format:"%h %an %cd" --

...and optionnally, just slightly easier for the eyes with a justified middle column :

git ls-files path/to/directory/ | xargs -n 1 git log -1 --pretty=format:"%h %<(20,trunc)%an %cd" --
Romain Valeri
  • 19,645
  • 3
  • 36
  • 61
  • Thanks for your answer, actually I'd also like to find the commit-hash + date which I managed to do using your solution with `git log -1 --pretty=format:"%h %an%cd" -- path/to/file` but ideally I'd like this list for *every* file (within some folder). – flawr Apr 08 '19 at 12:23
  • @flawr Yes I get what you'd like to obtain. I guess you'll need to loop over the files of the directory in some way, let me think about it :-) – Romain Valeri Apr 08 '19 at 13:10
  • I think I found a somewhat unwieldy solution that more or less works but is not very elegant, again using your suggestion: `for f in ./*.*; do echo $f; git log -1 --pretty=format:"%h %an %cd" $f; done` but please let me know if you find anything:) – flawr Apr 08 '19 at 13:20