DEV Community

Clarice Bouwer
Clarice Bouwer

Posted on

How to get a list of Git commits for a given file

This includes cases where the file has been renamed.

git log --follow filename.ext
Enter fullscreen mode Exit fullscreen mode

More on Stack Overflow: git log --follow, show all commits including merges

Top comments (3)

Collapse
 
labspl profile image
Wojciech

No space beetwen -- and filename

Collapse
 
cbillowes profile image
Clarice Bouwer

Thanks! Actually, the -- should be removed and the filename is the actual name of the file that you want to be follow. So an example would be

git log --follow package.json
Enter fullscreen mode Exit fullscreen mode

If the filename cannot be followed, Git will present you with a fatal: ambiguous argument 'package2.json': unknown revision or path not in the working tree error.

I am going to update the snippet. Let me know if you pick up any funnies with what I just posted.

Collapse
 
labspl profile image
Wojciech

Guess little tease is fine........

package2.json or package.json?