例如我有这样的提交:
comit1 user1
comit2 user2
comit3 user3
comit4 user1
comit5 user1
comit6 user2
comit7 user1
如何仅从 user1 提交提交?
comit1 user1
comit4 user1
comit5 user1
comit7 user1
如果无法使用cherry-pick,是否还有其他使用1,2命令的解决方案?
最佳答案
由于 user1
只有约 20 次提交,因此您可以将 gitcherry-pick
与 git log --author
结合起来:
git cherry-pick $(git log --pretty="%H" --author "user1" commit1~..commit7)
或者,您也可以使用 git rev-list
代替 git log
(git rev-list
相当于 git log -- Pretty="%H"如果您只对提交哈希感兴趣,则更短 – 感谢 @RomainValeri 指出了这一点!):
git cherry-pick $(git rev-list --author "user1" commit1~..commit7)
请注意,如果user1提交太多,此将会失败,因为gitcherry-pick
的参数数量(每个提交一个) commit) 会导致堆栈溢出。然而,there are workarounds for this .
关于git - 如何挑选特定作者的提交范围?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68574387/