Question

I want to get the log of all branch in only the current tree.

Long story

Given the git history below:

$ 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

Let say that I create a orphan branch.

$ git checkout --orphan orphan
Switched to a new branch 'orphan'

Add a commit in orphan branch and try to use the first command to get git history of the "second" tree.

$ 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

In the sample above, look like that 3d0cb35 is the father of 202f3c4 what isn't true. How can I get only the commit of only one of the trees?

Was it helpful?

Solution

I'm not sure there's a completely clean way to do what you want. But here's one suggestion... If you know that the set of branches you want to inspect is the one rooted at commit 3060fe0, then you can use git branch --contains 3060fe0 to identify the potential branches, and use that to feed your git log command. Something like:

git log ..... `git branch --contains 3060fe0`

But leave out the --all option, as that would override your explicit branch selection...

For convenience, you could drop a tag on each tree root, like git tag tree1 3060fe0, then you could just use git branch --contains tree1.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top