Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get/list/see all the descendants of a commit with git (or gitk)?

If you use gitk --all, you can see all the commits of your repo, from all branches. I want something like that except only the descendants of a given commit.

like image 490
Pistos Avatar asked Dec 11 '11 02:12

Pistos


People also ask

How do you check all commits of a file in git?

Use git log --all <filename> to view the commits influencing <filename> in all branches.

What is the git command to view all the commits made by a specific person?

The git log command displays all of the commits in a repository's history.


2 Answers

I think this might do what you want. All commits in all branches, that have A as ancestor:

gitk --all --ancestry-path A..
like image 134
jsvnm Avatar answered Oct 04 '22 12:10

jsvnm


In short:

git log --all BRANCH~1..

In detail, with examples: This is the complete tree of a repository I just created:

$ git log --graph --oneline --decorate --all
* e3972be (HEAD, a) a-6
* 2707d79 a-5
* cdea9a7 a-4
| * 65b716e (c) c-5
| * ebe2a0e c-4
|/  
| * 2ed9abe (b) b-4
|/  
* ace558e (master) 3
* 20db61f 2
* 3923af1 1

Aside from --all, another thing is obvious: master -> HEAD:

$ git log --graph --oneline --decorate master..
* e3972be (HEAD, a) a-6
* 2707d79 a-5
* cdea9a7 a-4

So I tried combining them, and it almost got me what we wanted:

$ git log --graph --oneline --decorate --all master..
* e3972be (HEAD, a) a-6
* 2707d79 a-5
* cdea9a7 a-4
* 65b716e (c) c-5
* ebe2a0e c-4
* 2ed9abe (b) b-4

But unfortunately, this doesn't show the relationship between the branches, since the branch we're asking about was omitted. So we have to use log from the parent of master like so:

$ git log --graph --oneline --decorate --all master~1..
* e3972be (HEAD, a) a-6
* 2707d79 a-5
* cdea9a7 a-4
| * 65b716e (c) c-5
| * ebe2a0e c-4
|/  
| * 2ed9abe (b) b-4
|/  
* ace558e (master) 3

Ta-da! (I don't know if this simply didn't work in the past, but just in case: I'm on git version 1.7.1)

EDIT 2017-11-17 - Thanks to STW for actually showing the problem with this: Independent trees would mess this up. Commits that are entirely independent of master would be included in this output. Starting from a copy of the above repo, this is what my last command would output:

$ git checkout --orphan z
Switched to a new branch 'z'
$ git commit --allow-empty -m'z-1'
[z (root-commit) bc0c0bb] z-1
$ git commit --allow-empty -m'z-2'
[z 1183713] z-2

$ git log --graph --oneline --decorate --all master~1..
* 1183713 (HEAD -> z) z-2
* bc0c0bb z-1
* 6069f73 (a) a-6
* 654d106 a-5
* a218c59 a-4
| * 338432a (c) c-5
| * 2115318 c-4
|/  
| * 43a34dc (b) b-4
|/  
* ce05471 (master) 3

The z branch, being created as an orphan, has no common history with master, so z-1 and z-2 should have been excluded but were not. This is what --ancestry-path is for, I now get. Including it will exclude branch z:

$ git log --graph --oneline --decorate --all --ancestry-path master~1..
* 6069f73 (a) a-6
* 654d106 a-5
* a218c59 a-4
| * 338432a (c) c-5
| * 2115318 c-4
|/  
| * 43a34dc (b) b-4
|/  
* ce05471 (master) 3

For completeness, even given that it already had --ancestry-path, the current top answer does not show the branch relationship correctly because it excludes the commit on master itself:

$ git log --graph --oneline --decorate --all --ancestry-path master..
* 6069f73 (a) a-6
* 654d106 a-5
* a218c59 a-4
* 338432a (c) c-5
* 2115318 c-4
* 43a34dc (b) b-4
like image 29
Izkata Avatar answered Oct 04 '22 13:10

Izkata