-1

I have created a branch test from master. Now git branch --contains $commitid for the commit to the master performed before the creation of the branch test shows that it belongs both to the master and the test:

git on  master [⇣?] 
❯ git log --oneline --all --graph
* f56a18a (tag: 0.12, origin/master) added 8
* 6eb3856 added 6
* a12dfb2 (HEAD -> master, tag: 0.11) added 6
* eff5df4 added 4
| * acf20e2 (origin/test) added 7
| * 86ec659 (test) added 5
|/  
| * a5d72eb (tag: 0.10) added 3
| * 84eded8 (tag: 0.9) added 3
|/  
* a449cf1 (tag: 0.8) added 3
* 9bf71a6 (tag: 0.7) added 3
* 2c9d219 (tag: 0.6) added 3
* 85bdd34 (tag: 0.5) added 3
* 26f2cd0 (tag: 0.4) added 3
* 52bd26a (tag: 0.3) added 3
* 5bfaece (tag: 0.2) added 3
* 2eef64e (tag: 0.1) added 3
* 3ee667e (tag: 0.0) added 3

git on  master [⇣?] 
❯ git branch --contains 3ee667e
* master
  test

Is there any way to filter out the branch the change was not committed to when doing git branch --contains?

altern
  • 5,829
  • 5
  • 44
  • 72
  • 1
    Despite the metaphor, changes are just not committed *to branches*. git doesn't store that metadata. – Romain Valeri Dec 23 '21 at 13:54
  • 1
    Git has no way of knowing which branch you were on when you did the commit. That commit belongs to both branches. – joanis Dec 23 '21 at 13:54
  • 2
    A commit isn't tied to any particular branch. The only question you can answer is if a commit is reachable from a branch, and in your case the commit you're asking about is reachable from both master and your test branch. With this knowledge, it might make more sense to rewrite your question to be "list all commits that are reachable from test that aren't also reachable from master". – Lasse V. Karlsen Dec 23 '21 at 13:54
  • Might want to read my https://www.biteinteractive.com/picturing-git-conceptions-and-misconceptions/ to learn what Git is, what a commit is, what a branch is. – matt Dec 23 '21 at 15:10

1 Answers1

1

No, that isn't how Git works. The name of the branch is not part of the commit, this information isn't retained anywhere.

user229044
  • 232,980
  • 40
  • 330
  • 338