Revision Selection

You can refer to one or many commits using git. Let’s look at how.

Short SHA-1 Hash Lookup

Git is smart enough to understand which commit you’re referring to with just the prefix of the hash. Using just the first 6 characters of the hash you can revise a commit.

We talked about git log and formatting the output. To log a short hash using the following

$ git log --abbrev-commit --pretty=oneline
ca82a6d Change the version number
085bb3b Remove unnecessary test code
a11bef0 Initial commit

Then you can do

$ git show 085bb3b 

Branch Reference

If you want to examine the last commit object on a branch, the following commands are equivalent, assuming that the topic1 branch points to commit ca82a6d…

$ git show ca82a6dff817ec66f44342007202690a93763949
$ git show topic1

So using the branch name you can see the latest commit easily.

RefLog Shortnames

Reflog is a log of where your HEAD and branch references have been for the last few months.

$ git reflog
734713b HEAD@{0}: commit: Fix refs handling, add gc auto, update tests
d921970 HEAD@{1}: merge phedders/rdocs: Merge made by the 'recursive' strategy.
1c002dd HEAD@{2}: commit: Add some blame and merge stuff
1c36188 HEAD@{3}: rebase -i (squash): updating HEAD
95df984 HEAD@{4}: commit: # This is a combination of two commits.
1c36188 HEAD@{5}: rebase -i (squash): updating HEAD
7e05da5 HEAD@{6}: rebase -i (pick): updating HEAD