简体   繁体   中英

How can I list related branches in git log

I am looking for a possibility to show the history of a given file together with the information in which branch the given commit is in.

Given this git repositority:

$ git log --graph --all --decorate=full --pretty=oneline --abbrev-commit 
* 3b116ab (refs/heads/br2) x
| * 8777a0a (HEAD -> refs/heads/br1, refs/heads/branch) g
| * 9be1f38 d
|/ 
| * 3a30d9c (refs/heads/master) d
| * e678c2f c
|/  
* faa3666 b
* 03ea6ad a

I need the history of a given file

$ git log --graph --all --decorate=full --pretty=oneline --abbrev-commit -- a
* 9be1f38 d
| * e678c2f c  
|/  
* faa3666 b
* 03ea6ad a

and the information in which branch which commit is in

$ git branch -a
* br1
  br2
  branch
  master

$ git branch -a --contains 9be1f38
* br1
  branch

$ git branch -a --contains e678c2f
  master

$ git branch -a --contains faa3666
* br1
  br2
  branch
  master

combined in one overview, something like

$ git magical-command
+ refs/heads/br2
| + HEAD -> refs/heads/br1, refs/heads/branch
| * 9be1f38 d
|/ 
| + refs/heads/master
| * e678c2f c
|/  
* faa3666 b
* 03ea6ad a

Of course in reality there would be much more commits not changing my file "a".

I think that might be not so unusual but I did not find anything like this. So any hint would be welcome.

You can get what you want, but a misconception needs clearing up first, don't skip this: commits can be ancestors of any number of commits, whatever names you're using in your local repo is irrelevant. Branch names refer to currently-particular commits in the history graph but they're strictly local; any correspondence among branch names used in any two repos is a matter of convenience or coincidence, the WIP branch in your repo from last night is almost certainly not related to the WIP branch in Sam's.

The command you're looking for is

git log --graph --decorate --oneline --ancestry-path --simplify-by-decoration --branches ^9be1f38

and those first three args are so useful I have

git config --global alias.lgdo '!f(){ git log --graph --decorate --oneline "${@---all}"; }; f'

so git lgdo gives a full overview, git lgdo @ gives a current-checkout history, and so on.

Your command would then be

git lgdo --ancestry-path --simplify-by-decoration --branches ^9be1f38

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM