Snabbreferens

Git-revisioner och intervallsyntax Snabbguide

En heltäckande referensguide för gitrevisions(7): commit-identifierare, relativa föregångare (~ och ^), reflog-syntax samt intervall med två och tre punkter.

· Publicerad

Common Revision Examples

Command Example Description
git log master...develop View symmetric difference between branches
git rebase -i HEAD~3 Interactively rebase the last 3 commits
git reset --hard HEAD@{2} Roll back to the state of HEAD two movements ago in reflog
git checkout v2^{} Dereference and checkout tag v2 as a commit (avoiding branch conflict)

Specifying Single Commits

Syntax Description
dae68e1 Abbreviated or full 40-character SHA-1 commit hash
HEAD Current checked-out commit
master Tip of branch named master
origin/master Tip of remote tracking branch
v1.0.0 Annotated or lightweight tag named v1.0.0

Relative Ancestry: ^ (Parent) and ~ (Generation)

Syntax Description
HEAD^ (or HEAD^1) The first parent of HEAD (immediate parent commit)
HEAD^2 The second parent of a merge commit
HEAD^^ Grandparent via first parent chain (HEAD^1^1)
HEAD~1 Same as HEAD^: 1 generation back
HEAD~2 2 generations back along the first-parent chain (HEAD^^)
HEAD~N N generations back along the first-parent chain

Reflog Syntax: @{n}

Syntax Description
HEAD@{0} Current position of HEAD
HEAD@{1} Position of HEAD prior to the latest checkout/commit
HEAD@{yesterday} Position of HEAD at a given timestamp
master@{2.weeks.ago} Tip of master as recorded 2 weeks ago

Upstream & Push Trackers

Syntax Description
@{upstream} (or @{u}) The configured remote-tracking branch for the current branch
@{push} The remote branch to which git push would publish

Revision Ranges

Two-Dot Range (r1..r2)

git log v1.0..master

Selects all commits reachable from master that are not reachable from v1.0. Equivalent to ^v1.0 master.

Three-Dot Symmetric Difference (r1...r2)

git log branch1...branch2

Selects commits reachable from either branch1 or branch2, but excludes commits shared by both.

Inverted Exclusions (^commit)

git log master ^origin/master

Commits in local master that have not yet been pushed to origin/master.

References

Relaterade ämnen