2

I want to find out what are the branches that a certain commit belongs to on GitHub but unlike most of the commits, this one does not display its branch on GitHub

a) enter image description here b) enter image description here I cloned the repository, and then ran git branch --contains <COMMITID> locally, but I got error: no such commit

However, on github I can navigate to the commit by passing the <COMMITID> in URL which I think contradict with the error I got earlier...

I suspect that a branch was deleted (I am not sure about remote branch deletion, but I think only the ref is removed and commits are left untouched?)...and the commit is not reachable (ignored when I git clone locally?)

if so how can I find more information about these "zombie commits"? if I am wrong, what actually happened? maybe a git revert?

1 Answer 1

3

A pull request is not a branch, it is a marker that says "I want to merge this feature branch into that other branch".

What has happened here is:

  1. Someone created a branch.
  2. A pull request was created to merge this branch.
  3. The branch was merged without the use of --no-ff, and then deleted.
  4. Then you cloned.

Since the commits from the now-deleted branch are unreachable, git doesn't necessarily bother to send them when you clone. Since they haven't yet been garbage collected on the remote, you can still see them when you navigate using the URL on GitHub (an operation equivalent to git show <somehash>).

Use of a merge commit (such as via --no-ff) would prevent the "original" commit from becoming unreachable when you merge. Rebase-then-merge leads to hashes changing, but no merge commits - some people don't like the clutter you get from merge commits.

You will probably find the history of the branch that got merged into contains an identical commit with a different hash. I do not believe there is a way to get a "clone-with-junk" that'd include this commit. git commit --mirror is the closest, but that just gets all refs....

Sign up to request clarification or add additional context in comments.

5 Comments

Maybe would you want to explain --no-ff?
I updated image to show another merge pull request, these two look alike (both have 2 parents...I think that means neither use fastforward) except that the one I want to investigate has no branch displayed on GitHub, what causes the difference?
If a commit is reachable via a branch or tag, git will send you it when you clone. If a commit is not reachable, git may not do so. The branches you see on github are just the branches present in the remote repo.
@ChrisKitching are you saying that the commit I am looking at uses fast forward? if so why does this extra commit exists (since ff doesn't require a commit for merge) ?
Fast-forward by itself wouldn't matter, but the combination of this with a rebase of the feature branch (a relatively common pattern) would. Sorry I wasn't clear: the fact the feature branch was rebased prior to merge is what has caused the hash to change. I merely meant to indicate no-ff as a way of ensuring this can't happen again (since it would discourage rebase-then-merge). If this bothers you, that is.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.