4

In an effort to improve stability, I'm currently refactoring all my Git-related shell scripts so that they use only plumbing (rather than porcelain) commands. In particular, I'm trying to replace calls to git log (porcelain) by calls to git rev-list (plumbing).

However, although git rev-list seems to offer much of the functionalities of git log, it seems to be missing an option equivalent to git log's --follow flag, which tells Git to list commits that affected a path even beyond renames (e.g. README -> README.md). From the git log man page:

--follow

Continue listing the history of a file beyond renames (works only for a single file).

I've sifted through the git rev-list man page, but I couldn't find any option that does the same as git log --follow. What am I missing? Can that be done with git rev-list? Or should I use another plumbing command altogether?

jub0bs
  • 60,866
  • 25
  • 183
  • 186

1 Answers1

2

Unfortunately, --follow is actually built (poorly) into git log itself. It turns on the rename-detection machinery, in a special one file only mode, and can then find backwards transitions (new file foo = old file bar).

(It does not find forward transitions, so that if you use --reverse and name a path that used to exist, e.g., with the intent of finding what file it became, it simply fails.)

torek
  • 448,244
  • 59
  • 642
  • 775
  • Hmmm... that's indeed unfortunate. My hopes have been dashed! – jub0bs Mar 24 '15 at 19:56
  • Incidentally that same code path is used in `git blame` which automatically does the equivalent of `--follow`. So there are *pieces* in there... I went to look at making it work with `--reverse` a while ago, and it got hairy, though. – torek Mar 24 '15 at 20:10
  • Thanks for that. It seems there would be room for refactoring. Perhaps I'll drop an email on the mailing list. But I'm curious...Running `git log --author=torek` in the Git-project repository doesn't return any hit. Are you involved under another name? – jub0bs Mar 24 '15 at 20:15
  • No, the only thing I've sent in to the git folks was a fix for "git stash", which they still haven't picked up. – torek Mar 24 '15 at 21:52
  • Good to know that you're a contributor. Maybe I will be too, one day. How long ago did you send them the fix? Maybe you should ping them on the mailing list... – jub0bs Mar 25 '15 at 10:31
  • 1
    I have a link in http://stackoverflow.com/a/20480591/1256452 to http://permalink.gmane.org/gmane.comp.version-control.git/234153 (it's a "possible" fix because I'm not a heavy stash user and perhaps there's some corner case it doesn't handle...). – torek Mar 25 '15 at 17:58
  • Thanks for the link. I'll give it a read, when I get the chance. – jub0bs Mar 25 '15 at 18:12