我想git filter-branch
对一个特定提交的所有孩子进行操作.这似乎不是一件容易的事,因为似乎没有办法告诉git rev-list
只返回特定提交的子代.使用..语法将不起作用,因为它还将包括该范围内任何合并的父提交.我在这里错过了什么吗?
澄清一下:我有一个被称为base
多次合并的分支derivative
.我想列出并最终继续运行filter-branch
它最近提交的提交.我还想在其他分支上列出类似的提交.
(简化)情况(derivative
左边的分支):
$ git rev-list --graph --oneline base derivative
* f16fd151b374b2aeec8b9247489c518a6347d001 merged in the latest from the base branch
|\
| * 564d795afb63eab4ffe758dbcd726ca8b790f9f6 spelling correction
* | 2f2ed5f1d429492e1491740e30be5a58ec20af21 snogg before flarg
|\ \
| |/
| * 0c520ea33ef57b30846b122781d41fcef5e62f9b now with added flarg
* | 5068c34c3862856f511b6b4d48f2adb766e1bde4 now with added snogg
|/
* b51f227e931f830cbda042bc372087398ae7e50d initial commit
Run Code Online (Sandbox Code Playgroud)
@ araqnid的建议似乎不起作用,除非我拙劣阅读它:
$ git rev-list --oneline derivative --not base
f16fd151b374b2aeec8b9247489c518a6347d001 merged in the latest from the base branch
2f2ed5f1d429492e1491740e30be5a58ec20af21 snogg before flarg
5068c34c3862856f511b6b4d48f2adb766e1bde4 now with added snogg
Run Code Online (Sandbox Code Playgroud)
因为这提供了derivative
除了提交之外的所有提交base
.这种做法是有道理的,因为它所做的就是删除否定提交的祖先.我希望它展示的只是第一行.
好吧," - 分支"或"--all"将包括所有分支提示,然后" - not A"将排除A及其所有祖先.但是," - branch - not A"将包含不包含A的分支,我认为这不是您需要的.
尽管你可以解决问题,但没有简单的方法来获得你想要的一切.这将列出包含提交A的所有分支:
git for-each-ref refs/heads/* | while read rev type name; do
git rev-list $rev | grep $(git rev-parse A) >/dev/null && echo $rev
done
Run Code Online (Sandbox Code Playgroud)
然后你需要列出所有可以从这些修订中获得的修订,但不能列出A本身和任何修订版本
git rev-list $(git for-each-ref refs/heads/* | while read rev type name; do
git rev-list $rev | grep $(git rev-parse A) >/dev/null && echo $rev
done) --not A
Run Code Online (Sandbox Code Playgroud)
请注意,我只给出了一个非常简短的测试:p但我认为基本面是合理的.
显示A
要从其他一组提交的祖先路径:
显示仓库中所有无法访问的提交:
git fsck
--unreachable --no-reflogs \
| awk '$2 == "commit" {print $3}'
A
在repo中的任何位置跟踪提交的所有后代:
git log --ancestry-path --graph --decorate --oneline ^A \
--all $(git fsck --unreachable --no-reflogs | awk '$2=="commit" {print $3}')
Run Code Online (Sandbox Code Playgroud)
显示其历史记录包含提交的所有引用:
git log --ancestry-path --graph --simplify-by-decoration --oneline --all ^A
# and in case A might have a direct ref, add:
git log --ancestry-path --graph --simplify-by-decoration --oneline A^!
Run Code Online (Sandbox Code Playgroud)
编辑:更正:当A
父母与其他孩子在一起时,不要显示不需要的提交.