Why does a Git commit seem to be missing from the branch I expected?
Quick answer
A commit may be on a different branch, have been made while HEAD was detached, or be outside the history range you are viewing. Start by checking git branch, then inspect recent history with git log --oneline -n 20 and review git reflog. These checks can help locate the commit before you change references. Reflog entries are local, and their availability depends on what the repository recorded. [S1] [S2] [S3]
The question, the details, the next step.
A practical checklist
Run
git branchand check whether you are on the expected branch or in detached HEAD state. [S1]Inspect recent history with
git log --oneline -n 20; note that the output is limited. [S3]Check the exact references, range, and display limit used by your history view. [S3]
Review
git reflogfor local reference updates and branch switches. [S2]Before attempting recovery, verify the commit ID and decide which branch should contain it.
A few more useful answers
Does not finding a commit in a log display prove it is lost?
Is the reflog a shared record for everyone using the repository?
No. Reflog history is local to the repository; its entries are not a shared record. [S2]
Should I change a branch as soon as I find a likely commit?
First confirm the commit ID and decide which branch should contain it. Locating a commit is an inspection step; changing references is a separate recovery step.
Sources
References used for this guide.
- [S1] Git User Manual: Detached HEAD git-scm.com · Checked
- [S2] Git - git-reflog Documentation git-scm.com · Checked
- [S3] Git - git-log Documentation git-scm.com · Checked
