Pointing to branches
HEAD is used to represent the current snapshot of a branch. For a new repository, Git will, by default, point HEAD to the main branch. Changing where HEAD is pointing to will update your active branch.
The ~(tilde) and ^(caret) symbols point to a position relative to a specific commit. The symbols are used with a commit reference, typically HEAD or a commit hash.
- ~ refers to ancestors (how many generations back depends on the number).
- HEAD~1 refers to the commit’s first parent.
- HEAD~2 refers to the commit’s first grandparent.
- ^ refers to parents of merge commits.
- HEAD^1 refers to the first parent of HEAD where head is a merge commit.
- HEAD^2 refers to the first grandparent of HEAD where head is a merge commit.
A commit can have two parents in a merge commit.
