gitgitlab

Git commit no longer in the log after `git pull`


Yesterday I cloned a Git repository (hosted on a GitLab instance). The HEAD was some commit (26337128). Today, I did a git pull, but this commit no longer appears in the log (git log | grep 26337128 and git branch -a --contains 26337128 both give nothing). Why?

Note that the commit is still visible with git show 26337128 (and on the GitLab web interface), I did not do any local change, and I am still in the default branch.

EDIT: Here's git reflog --all output, but I don't know how to interpret it:

8d0f83b389ec (HEAD -> drm-tip, origin/drm-tip, origin/HEAD) refs/heads/drm-tip@{0}: pull (finish): refs/heads/drm-tip onto 8d0f83b389ec64b9f7f9b2ee241fc352346868f1
8d0f83b389ec (HEAD -> drm-tip, origin/drm-tip, origin/HEAD) HEAD@{0}: pull (finish): returning to refs/heads/drm-tip
8d0f83b389ec (HEAD -> drm-tip, origin/drm-tip, origin/HEAD) HEAD@{1}: pull (start): checkout 8d0f83b389ec64b9f7f9b2ee241fc352346868f1
8d0f83b389ec (HEAD -> drm-tip, origin/drm-tip, origin/HEAD) refs/remotes/origin/drm-tip@{0}: pull: forced-update
26337128da9b refs/heads/drm-tip@{1}: clone: from https://gitlab.freedesktop.org/drm/tip
26337128da9b refs/remotes/origin/HEAD@{0}: clone: from https://gitlab.freedesktop.org/drm/tip
26337128da9b HEAD@{2}: clone: from https://gitlab.freedesktop.org/drm/tip

Solution

  • The commit you're asking about is present in your local repo; it is listed in the bottom three lines of the reflog.

    As for what happened: Well, it would be more helpful if you said git reflog --date iso so we could see how much time elapsed between your actions; but, based on the reflog and the little hints you've dropped for us, evidently between your clone yesterday and your pull today, someone did a force push (notice the "pull: forced-update") — and so 26337128 was ripped out of the rewritten branch.

    Of course, people are not supposed to do that kind of thing (force push to a shared branch). But evidently your gitlab remote isn't configured to prevent it.

    Anyway, you do still have that commit if you want it (for now). Since it isn't on any branch any more, it will eventually be garbage collected if you don't pin it. For now, the reflog itself is retaining the commit.