Dev Notes

Various Cheat Sheets and Resources by David Egan/Carawebs.

Finding Files in git History


Git
David Egan

You may need to find a file in your commit history - perhaps the file was deleted, and you need the functionality that it contained.

Show Commits where the File Changed

This will show commits where the file changed, even if the file has been deleted:

git log -- /path/to/target/file

This will provide a log of commits that involved the specified file changing.

View the Commit Associated with File Deletion

git log -1 -- /path/to/target/file

This shows the last commit that contained the file. You could specify a different number to see the last x commits.

View the Relevant Commit

Once you have determined the commit reference, you can view the file by selecting the relevant in an online repo.

You could also check out the commit:

git checkout d33ffc9

If you checkout the commit, you can view and edit files without affecting the current state of the project. You need to checkout your working branch (usually ‘master’) to go back to work.

It’s usually enough to grab the commit reference and view this in the online repo (Bitbucket or Github).

Resources


comments powered by Disqus