How to find all links containing commit in your story in git

Suppose you have the following structure in git

    A <-- refs/heads/somebranch
    |
    B 
    | \
    C  D <-- refs/tags/TAG1
    |  |
    E  F
    |  | \
    G  H  I <-- refs/heads/branch1                
    |
    J <-- refs/heads/master

Now I want to find all the links containing commit Bin my story.

So it would be nice if I could do

$ git refs --contains B
refs/tags/TAG1
refs/heads/branch1
refs/heads/master

I looked at git decumentation and found git branch -a --contains <commit_id>which lists all branches containing commit_id.

$ git branch -a --contains 4af9822
  master
  remotes/origin/someBranch
  ...

and i found a team git tag --contains 9338f2d

$ git tag --contains 9338f2d
  someTag
  anotherTag
  ...

Of course, I can do something like this,

$ git branch -a --contains 4af9822 && git tag --contains 9338f2d

but is there a command that displays all the links at once?

+4
source share
2 answers

To add torek's answer, git 2.7 (Q4 2015) will offer a more complete version git for-each-ref, which now support--contains

git for-each-ref --contains <SHA1>

. commit 4a71109, ee2bd06, commit f266c91, 9d306b5, commit 7c32834, commit 35257aa, commit 5afcb90, d325406, commit 6841104, commit b2172fd, commit b2172fd,..., commit b2172fd (07 2015 .) af83baf (09 2015 .) Karthik Nayak (KarthikNayak).
( Junio ​​C Hamano - gitster - commit 9958dd8, 05 2015 .)

"git tag -l" "git branch -l" "git for-each-ref", , .

* kn/for-each-tag-branch:
  for-each-ref: add '--contains' option
  ref-filter: implement '--contains' option
  parse-options.h: add macros for '--contains' option
  parse-option: rename parse_opt_with_commit()
  for-each-ref: add '--merged' and '--no-merged' options
  ref-filter: implement '--merged' and '--no-merged' options
  ref-filter: add parse_opt_merge_filter()
  for-each-ref: add '--points-at' option
  ref-filter: implement '--points-at' option  

, git 2.13 (Q2 2017), git for-each-ref --no-contains <SHA1>, , !

. commit 7505769, commit 783b829, commit ac3f5a3, commit 1e0c3b6, commit 6a33814, c485b24, commit eab98ee, commit bf74804 (24 2017 .), commit 7ac04f1, commit 682b29f, commit 4612edc, commit b643827 (23 2017 .) 17d6c74, 8881d35, commit b084060, 0488792 (21 2017 .) Γ†var ArnfjΓΆrΓ° Bjarmason (avar).
( Junio ​​C Hamano - gitster - commit d1d3d46, 11 2017 .)

+7

[ , 2015: VonC], git branch -a --contains git tag --contains , "".

( ) . , " ", git for-each-ref. :

$ git for-each-ref
996b0fdbb4ff63bfd880b3901f054139c95611cf commit refs/heads/master
740c281d21ef5b27f6f1b942a4f2fc20f51e8c7e commit refs/remotes/origin/maint
996b0fdbb4ff63bfd880b3901f054139c95611cf commit refs/remotes/origin/master
7327a17171fc87d5f8f5c790eb1ba1d0e031482d commit refs/remotes/origin/next
[... snip]
efe35e936c6c32a7630086a84b2c3b3471ea534f tag    refs/tags/v2.0.1
b4463ead04f1801104502ea087dbb6bdd21b4ef1 tag    refs/tags/v2.0.2
3c81e95201ece182e799709c91b15a3501919d26 tag    refs/tags/v2.0.3

( git for-each-refs git , ).

, , --contains . , , --contains git merge-base, --is-ancestor. git branch , --contains , - SHA-1, refs/heads/ refs/remotes/ - . " " , " ", :

$ git branch --contains 996b0fd^
* master
$ git rev-parse 996b0fd^
6da748a7cebe3911448fabf9426f81c9df9ec54f

master 996b0fd..., --contains 996b0fd, 6da748a..., , git merge-base --is-ancestor:

$ git merge-base --is-ancestor 6da748a 996b0fd && echo ok
ok

, 996b0fd :

$ git merge-base --is-ancestor 996b0fd 996b0fd && echo ok
ok

, , , git for-each-ref , git merge-base --is-ancestor.

+5

All Articles