gpt4 book ai didi

git - 列出 Git 在 a 和 b 之间的提交,仅考虑 b 的第一个 parent 和 a 的第一个 parent

转载 作者:行者123 更新时间:2023-12-01 23:54:50 26 4
gpt4 key购买 nike

使用 Git,您可以列出 b 的所有祖先, 不包括 a 的所有祖先:

git log a..b

您还可以列出 b 的所有第一亲 祖先, 不包括 a 的所有祖先:

git log --first-parent a..b

但我想列出 b 的所有第一亲 祖先, 不包括 a 的所有第一亲 祖先.我还没有找到任何方法让第一 parent 要求也适用于修订范围的负面部分。

有没有办法做到这一点?如果仅使用 Git 命令无法做到这一点,是否有一种合理的方法可以使用 Bash 脚本来实现?


更多细节。对于此提交图(父项按从左到右的顺序显示):

    b --> 9
|\
| \
| \
a --> 6 7 8
|\ | |
| \ | |
| \| |
3 4 5
\ | /
\ | /
\|/
2
|
|
1

git log a..b将列出 9、8、7 和 5。git log --first-parent a..b会列出 9 和 7。我正在寻找一种方法来列出 9、7 和 4。

最佳答案

您可以构建两个列表,并使用 grep 将一个列表从另一个列表中排除:

git rev-list --first-parent a > lista.txt
git rev-list --first-parent b > listb.txt

# use grep, use '-f' to read patterns from 'lista.txt',
# use '-v' to say "exclude these patterns"
cat listb.txt | grep -v -f lista.txt

您可以避免在磁盘上创建文件;在 bashzsh您可以使用所谓的进程替换(语法为:<(command)):

git rev-list --first-parent b | grep -v -f <(git rev-list --first-parent a)

可以与 grep 一起使用的一个额外标志是-F, --fixed-strings ) :因为在这种情况下所有模式都是扁平字符串(不是正则表达式),您可以将其指示为 grep , 它加快了速度

git rev-list --first-parent b | grep -v -F -f <(git rev-list --first-parent a)

关于git - 列出 Git 在 a 和 b 之间的提交,仅考虑 b 的第一个 parent 和 a 的第一个 parent ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62943962/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com