简体   繁体   English

如何在 git log 中列出相关分支

[英]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 存储库:

$ 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".当然,实际上会有更多的提交不会改变我的文件“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.任何两个 repo 中使用的分支名称之间的任何对应关系都是方便或巧合的问题,您昨晚的 repo 中的WIP分支几乎肯定与 Sam's 中的WIP分支无关。

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.所以git lgdo给出了一个完整的概述, git lgdo @给出了当前的结帐历史,等等。

Your command would then be你的命令将是

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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