watashiSHUN
watashiSHUN

Reputation: 10484

Find the branch of a commit on github

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?

Upvotes: 2

Views: 174

Answers (1)

Chris Kitching
Chris Kitching

Reputation: 2655

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....

Upvotes: 3

Related Questions