Recent chats
ASKGEEZ Q&A GUIDETechnology & devices

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]

LET’S WORK THROUGH IT

The question, the details, the next step.

Question

I made a commit, but it is not showing on the branch I expected. What should I check first?

Geez

Start with read-only checks; avoid commands that change branch or commit references while you are still looking for the commit. Run:

git branch

Then inspect recent history:

git log --oneline -n 20

Compare the branch you expected with the one you are on, and look for the commit in the log. The log command is limited to 20 entries here, so not seeing the commit in that output does not by itself show that it is lost. Git history commands can display different commits depending on the references and range selected. [S3]

Follow-up question

The branch name is not what I expected. Could the commit be on another branch, or did I commit without one?

Geez

Either is possible. A commit made on another branch may not appear in the branch history you expected. Also, git branch indicates detached HEAD state. In that state, HEAD identifies a commit rather than a branch, so a commit made there may not appear in the expected branch history. [S1]

Use git branch to orient yourself, then compare the branch names and recent commit IDs shown by the history you are inspecting. Keep this as an investigation: the goal is to identify where the commit appears before changing any references.

Follow-up question

I can’t see it in the recent log. How do I tell whether I’m looking at too little or at the wrong range?

Geez

Check the exact command or history view you used. Note which references it starts from, whether it specifies a range, and whether it limits the number of commits shown. Git’s log range affects what appears: for example, git log A..B lists commits reachable from B but not A. A commit can therefore be absent from a particular display without that alone meaning it is lost. [S3]

As a simple next check, use a larger limit:

git log --oneline -n 50

If you know the suspected commit ID, compare it with the IDs shown. Remember that increasing the limit does not change which references or range the command uses. If you used a range before, inspect that range rather than assuming the shorter output covered all relevant history.

Follow-up question

It still isn’t there. What does the reflog tell me, and what should I do if I find the commit?

Geez

Inspect the local reference history with:

git reflog

Reflogs record updates to local branch and other reference tips; the HEAD reflog also records branch switching. Its entries may help you locate a commit or position that is no longer the current expected tip. Reflog history is local, and what you can find depends on the entries recorded in this repository. [S2]

Look for an entry around the time you committed or switched branches, and note its commit ID. Before attempting recovery, verify that it is the commit you intended and decide which branch should contain it. The checks above help locate evidence; they do not move the commit onto a branch. If you are unsure about the next step, get someone familiar with the repository to review your plan before changing references.

A practical checklist

  • Run git branch and 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 reflog for 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?

No. The selected references, range, and display limit affect which commits appear. A local reflog may offer another clue, but its entries depend on what the repository recorded. [S2] [S3]

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.

  1. [S1] Git User Manual: Detached HEAD
    git-scm.com · Checked
  2. [S2] Git - git-reflog Documentation
    git-scm.com · Checked
  3. [S3] Git - git-log Documentation
    git-scm.com · Checked

YOUR QUESTION. YOUR DETAILS.

Let’s work through your situation.

Get a tailored answer or help with your next task. Starts at $1, with a quote before you pay.

Ask your own question
← Back to Geez at Work