4

I can list commits for a file, even if it has been renamed or moved

git log --follow foo.sh

However, I would like to "follow" the file, but only list commits where the file was actually changed. Something like

git log --follow --exclude-renames foo.sh
Zombo
  • 1
  • 62
  • 391
  • 407
  • I tried to filter it by commit message with `--grep="renamed:" --invert-grep` but for me this did not work. But the oposide direction `--grep="renamed:"` forks and shows only commits containing the "renamed:" test in the message. But keep in mind that it if only a filtering by message, this can not respect commits with mixed renames and changes. – Radon8472 Oct 21 '20 at 00:24

3 Answers3

2
git log --follow --name-status --oneline foo.sh | sed 'h;N;/\nR/d;g'
  • copy commit line to hold space
  • read in second line
  • if line starting with R is found, delete pattern space and start next cycle, else copy hold space to pattern space

thanks to jthill

Community
  • 1
  • 1
Zombo
  • 1
  • 62
  • 391
  • 407
1

A bit like in "nicely display file rename history in git log", you could add --name-status in order to:

  • not select (grep -v renames: status 'Rxxx', while keeping addition 'A' or modification 'M')
  • still follow the file through its different name

But that will still involve post-processing the git log command (with grep and/or sed) in order to get the output you want: there is no native '--exclude-renames'-like option yet.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • seeing as how the '--exclude-renames' option is exactly two bytes shorter than just supplying the sed to do it, I have a hard time seeing the point of yetanotheroptionname ... :-) – jthill Feb 28 '13 at 18:57
1

just found --diff-filter option, which you can exclude renames by

--diff-filter=r

so,

git log --follow --diff-filter=r foo.sh

thanks for @Zombo answer about --name-status option

Puttin
  • 1,596
  • 23
  • 27