ORIG_HEAD
stores the previous state ofHEAD
before executing risky commands.- It is set by commands that change
HEAD
by more than one commit (e.g.merge
,rebase
,reset
).ORIG_HEAD
is not always set, as it only updates during these specific operations.
HEAD@{1}
refers to the last value ofHEAD
before the most recent change.- Unlike
ORIG_HEAD
,HEAD@{1}
is always available.- It pulls from the reflog specific to the current branch, tracking the changes made to that branch rather than just
HEAD
.
- It pulls from the reflog specific to the current branch, tracking the changes made to that branch rather than just
Note:
@
refers to the current commit thatHEAD
points to.
HEAD@{x}
is useful for referencing a specific state from your reflog history. For example:
git reset --hard HEAD@{1}
This will reset the current branch to the commit before the most recent HEAD
change, which could be from a commit, merge, or rebase.
git checkout HEAD@{2}
This is useful if you want to explore or inspect how the branch looked two changes prior.
git reflog
This will show you a list of previous states HEAD
has gone through, with the index (HEAD@{0}
, HEAD@{1}
, etc.) that you can use to reference each state.