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

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

+5
source share
3 answers

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

gitk --all --ancestry-path A..
+7
source

A commit only knows about its parent (and therefore about it), but does not have a clue about its descendants / descendants. You must use a type designation A..B to find it.

, A, - :

git rev-list A..
+2

:

git log --all BRANCH~1..

, : :

$ 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

--all, : masterHEAD:

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

, , , :

$ 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

, , , , , ​​ . log master :

$ 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

-! ( , , : git 1.7.1)

EDIT 2017-11-17. STW : . , master, . , :

$ 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 branch z, created as an orphan, has no common history with master, z-1and therefore z-2should be excluded, but were not. This is what for --ancestry-path, now I get. Inclusion in it excludes the 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 if it already has one --ancestry-path, the current top answer does not show the branch relation correctly, because it excludes fixing to masteritself:

$ 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
+1
source

All Articles