git-revisions

neevop 七月 2, 2023


用法示例

# inspect differences between branches
git log master...develop

# rebase last 3 commits
git rebase -i HEAD-3

# undo last operation that changed HEAD
git reset --hard HEAD@{2}

# checkout v2 tag not v2 branch
git checkout v2^{}

common git revisions

reference description
git show abced1 sha1
git show HEAD reference
git show v1.0 tag
git show master local branch
git show origin/master remote branch
git show master-2 2 commits back from master
git show master..fix reachable from fix but not master
git show master…fix reachable from master and fix, but nor both

reference

example description
git checkout HEAD reference
git checkout master branch
git checkout v1.0.0 tag
git checkout origin/master aka, refs/remotes/origin/master
git checkout heads/master aka, refs/heads/master

searching back

example description
git checkout master@{yesterday} also 1 day ago, etc
git checkout master@{2} 2nd prior value
git checkout master@{push} where master would push to
git checkout master^ parent commit
git checkout master^2 2nd parent, eg, what it merged
git checkout master-5 5 parents back
git checkout master^0 this commit, disambiguates from tags
git checkout v0.99.8^{tag} can be commit, tag, tree, object
git checkout v0.99.8^{} defaults to {tag}
git checkout “:/fix bug” searches commit messages

ranges

# reachable parents from master
git log master

# exclude reachable parents from master
git log ^master

# parents for head
git log HEAD^@

# HEAD, then excluding parents' ancestors
git log HEAD^!

# search previous HEADs matching criteria
git log HEAD^{:/fix}