List the commits that changed a file

Lets say you deleted a file in your branch and you later real­ize that you need it back. If you remem­ber the file path + file­name, you can eas­ily check which was the last com­mit that involved this file by the command

git log -1 -- [file path]

Now that you know which com­mit sha deleted the file, you can eas­ily do a git check­out from there and get it back.

If you omit the –1 option, it will list you all the com­mits in which that par­tic­u­lar file was mod­i­fied in reverse chronolo­gial order.


Ryan Sukale

Ryan is just a regular guy next door trying to manage his life and finances.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *