The official documentation for this syntax is in the gitrevisions
manpage.
HEAD~1
means: go back 1 commit from HEAD
, using the first parent (most commits have only one parent, so this syntax covers most cases where you want to go further back).
HEAD~1
is so common that it can also be shortened to HEAD~
.
It's important to understand, though, that HEAD
has little to do with the state of the origin repository! HEAD~1
will happen to match the current state of the origin in these cases:
- You just pulled (merged) from the origin, and it created a merge commit (prompted for a merge commit message).
- You were up-to-date with the origin and then made a single new commit on top.
In other cases you would probably use @{upstream}
which references the upstream of your current branch (also documented in the gitrevisions
manpage).
Finally, --soft
often isn't the right choice, either. It means that all your changes will be preserved in the working tree and index. Your files won't change at all, and git status
will show all the changes as "to be committed".
If you want to basically hit the reset button and irrevocably destroy all committed and uncommitted changes you have locally compared to the upstream, I recommend this:
git reset --hard @{upstream}