- HEAD refers to the latest commit on the current branch.
- HEAD^ refers to the parent commit of HEAD.
- HEAD^^ refers to the grandparent commit, and so on.
HEAD~n
: Refers to the commit n commits before HEAD. For example,HEAD~2
refers to the second ancestor commit.
HEAD^n
: Refers to the nth parent of a merge commit, useful for merge commits with more than two parents.
A..B
: Refers to all commits reachable from B but not from A (commits in B that are not in A).
A...B
: Refers to all commits in both A and B, except for those reachable by both (symmetric difference).
+branch_name
: Forces an update by discarding any in-progress changes.
git log HEAD~3..HEAD
: Shows the log for the last three commits up to the current HEAD.
git diff master..feature
: Shows the difference between themaster
branch and thefeature
branch, displaying changes exclusive tofeature
.
git log branchA...branchB
: Lists all commits that are inbranchA
orbranchB
but not in both, helping to understand divergent histories.
git reset --hard HEAD^
: Moves the current branch pointer to the parent of the current commit, discarding all changes since that commit.
git push origin +master
: Forcefully updates the remotemaster
branch to match the localmaster
, potentially overwriting changes on the remote.