仅当前树中所有分支的 Git 日志

Ran*_*lva 3 git git-log git-branch

我想获得的所有分支的日志中只有当前树。

很长的故事

鉴于下面的 git 历史:

$ git log --all --decorate --oneline --graph
* 3d0cb35 (HEAD, master) 4th commit
| * a43b07c (branch) 4th commit in branch
|/  
* 722745a 3rd commit
* 46d0d84 2nd commit
* 3060fe0 1st commit
Run Code Online (Sandbox Code Playgroud)

假设我创建了一个孤儿分支。

$ git checkout --orphan orphan
Switched to a new branch 'orphan'
Run Code Online (Sandbox Code Playgroud)

在孤儿分支中添加一个提交并尝试使用第一个命令来获取“第二个”树的 git 历史记录。

$ git log --all --decorate --oneline --graph
* 202f3c4 (HEAD, orphan) Orphan branch
* 3d0cb35 (master) 4th commit
| * a43b07c (branch) 4th commit in branch
|/  
* 722745a 3rd commit
* 46d0d84 2nd commit
* 3060fe0 1st commit
Run Code Online (Sandbox Code Playgroud)

在上面的示例中,看起来这3d0cb35就是202f3c4不真实之父。我怎样才能得到只有犯下的唯一的一棵树上?

twa*_*erg 5

我不确定有没有一种完全干净的方式来做你想做的事。但这里有一个建议...如果您知道要检查的一组分支是根植于 commit 的分支3060fe0,那么您可以使用它git branch --contains 3060fe0来识别潜在的分支,并使用它来提供您的git log命令。就像是:

git log ..... `git branch --contains 3060fe0`
Run Code Online (Sandbox Code Playgroud)

但是不要选择这个--all选项,因为这会覆盖你的显式分支选择......

为方便起见,您可以在每个树根上放置一个标记,例如git tag tree1 3060fe0,然后您就可以使用git branch --contains tree1.