git - 如何挑选特定作者的提交范围?

标签 git git-cherry-pick

例如我有这样的提交:

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-pickgit 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/

相关文章:

git - 为什么 `git cherry-pick` (没有 `--no-commit` )不运行我的提交后钩子(Hook)?

Eclipse 4.6.1 JGit/EGit 升级后验证时间更长

macos - 如何取消我的计算机与 github 帐户的链接?

由于已删除文件,无法进行 git merge

git - 如何为多个文件(或所有未 merge 的文件)执行 'git checkout --theirs'

Git 在不切换的情况下 pull 非工作分支

git - 限制对 GIT 的挑选

git - 如何解决 "git pull" merge 冲突到我之前的提交之一?

git - 在不存在的文件中进行更改的 Cherry-pick

Git 将一个分支复制到另一个分支