Suggest an editImprove this articleRefine the answer for “What is the difference between HEAD~1 and HEAD^?”. Your changes go to moderation before they’re published.Approval requiredContentWhat you’re changing🇺🇸EN🇺🇦UAPreviewTitle (EN)Short answer (EN)**`HEAD~1`** is the previous commit along the chain, and **`HEAD^`** is the parent of the commit. **Key point:** in regular (non-merge) commits they are the same; the difference appears only with a merge, where `^` lets you pick a specific parent while `~` always follows the first line of history.Shown above the full answer for quick recall.Answer (EN)Image## Short answer - `HEAD~1` is the *previous commit along the chain* - `HEAD^` is the *parent of the commit* In **regular (non-merge) commits** they are **the same**. The difference appears **only with a merge**. --- ## `HEAD~1` - one step back through history Notation: ```bash HEAD~1 ``` Means: - "take the first parent" - "go one commit back" You can continue: ```bash HEAD~2 HEAD~3 ``` So `~` is **the number of steps back**. --- ## `HEAD^` - the parent of a commit Notation: ```bash HEAD^ ``` Means: - "the first parent of the current commit" A merge commit has several parents: ```bash HEAD^1 # first parent HEAD^2 # second parent ``` --- ## Where the difference shows up (the key point) Imagine a merge commit: ``` C---D (feature) / \ A---B-------M (main) ``` - `HEAD` → `M` - `HEAD^1` → `B` (the `main` branch) - `HEAD^2` → `D` (the `feature` branch) - `HEAD~1` → `B` (always the first parent) `~` **always follows the first line of history**, `^` **lets you choose which parent to take**. --- ## Important takeaway for interviews - `HEAD~1` ≡ `HEAD^` **if the commit is not a merge** - with a merge: - `~` - only the main path - `^` - access to specific parents --- ## Short table | Notation | What it means | |---|---| | `HEAD~1` | one commit back | | `HEAD~2` | two commits back | | `HEAD^` | first parent | | `HEAD^2` | second parent (merge) | --- ## Short answer for an interview > `HEAD~1` is a move to the previous commit along the main line of history. > `HEAD^` is the parent of a commit. In regular commits they are the same, but with a merge, `^` lets you pick a specific parent, while `~` always follows the first one. --- ## A frequent mistake "These are just two ways of writing the same thing" is wrong. They match **only in linear history**.For the reviewerNote to the moderator (optional)Visible only to the moderator. Helps review go faster.