reflog - When You Don't Know the Commit ID

What is git reflog (git Reference Log)?
- git reflog is a Git command that shows every record of where references such as HEAD and branches have moved.
- Simply put, think of it as a log that records "the history of every commit HEAD has pointed to" in chronological order.

Key Features and Uses
Checking HEAD's movement history
- Every time HEAD moves through a commit, checkout, reset and so on, a record is left.
- Even if you accidentally move a branch or remove a commit, you can find the old position in reflog.
Recovering commits
You can bring back commits that disappeared (became invisible) because of
git reset,git checkout,git commit --amendand so on.For example, you can easily go back to a commit that disappeared because of a reset.
bashgit reflog # find the commit hash or HEAD@{n} you want in the log git reset --hard HEAD@{2} # recover to that position
Works even if you don't know the commit ID
- Even if you forget the commit hash, you can check the full movement history with reflog and go back to the point you want.
How to Use It
Basic usage
bashgit reflog- Shows the movement history based on HEAD.
Recover to the point you want
bashgit reset --hard [commit ID or HEAD@{n}]
Summary
git reflog: a record of every position HEAD has pointed to- Commits that seem to have disappeared because of reset and the like can be recovered with
git reset --hard HEAD@{n}
Reference: personal Notion study notes (Git study)
