Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does git log with --follow and --reverse return only last commit?

Tags:

git

I wanted to view all the commits of a file from the beginning in reverse I ran

git log --reverse [file]

And it worked as expected. but for a renamed file it shows only from the commit in which it was renamed so I added --follow in it.

git log --reverse --follow [file]

but it now shows only the last commit which was done for that file.

How can I combine both to get the desired result.

like image 765
Shubanker Avatar asked Feb 13 '16 11:02

Shubanker


People also ask

How does git log follow work?

With git log --follow , Git runs an after-diff step (called from diff_tree_sha1 ; see footnotes) that trims everything down to one file. The diff is done with R=C and L=P.

How do I revert to most recent commit in git?

The easiest way to undo the last Git commit is to execute the “git reset” command with the “–soft” option that will preserve changes done to your files. You have to specify the commit to undo which is “HEAD~1” in this case. The last commit will be removed from your Git history.

Does git log show all branches?

Graph all git branches Developers can see all branches in the graph with the –all switch. Also, in most situations, the –decorate switch will provide all the supplemental information in a formatted and nicely color-coded way.


1 Answers

This seems to be known bug in git. The only work around I can see is if you know what the file was named before, pass it along with the current file to the command, i.e.

 git log --reverse --follow -- oldfilename currentfilename

Edit: the following will do what you want:

git log --name-only --pretty="format:"  --follow <filename> | sort -u | xargs git log --reverse --
like image 81
David Deutsch Avatar answered Oct 23 '22 17:10

David Deutsch