git - 如何在 Git 存储库中找到具有多个父级的所有提交?

标签 git

我正在开展一项研究,研究开源项目中的 merge 。

对于存储库中的每次 merge ,我需要找到基础(最近的共同祖先)、两个贡献者以及生成的 merge 提交。

我已经知道如何获取最近的共同祖先 ( git merge-base rev1 rev2 ) 和贡献者 ( git log --pretty=%P -n 1 <commit> ),但我在识别 merge 操作产生的提交时遇到问题。

如何在 Git 存储库中找到具有多个父级的所有提交?

最佳答案

这应该足够了(对于本地提交)

 git rev-list --merges

git rev-list man page提及:

--merges

Print only merge commits. This is exactly the same as --min-parents=2.

这意味着 rev-list 有一些有趣的过滤器:

--min-parents=<number>
--max-parents=<number>

Show only commits which have at least (or at most) that many commits.
In particular:

  • --max-parents=1 is the same as --no-merges,
  • --min-parents=2 is the same as --merges.
  • --max-parents=0 gives all root commits and
  • --min-parents=3 all octopus merges.

关于git - 如何在 Git 存储库中找到具有多个父级的所有提交?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15637494/

相关文章:

git - 如何将我的 git 存储库克隆到远程计算机?

git - 使用 Egit 共享项目中的目标位置

git - 如何在 GitHub 中仅使用我的分支存储库的主分支中的最新提交执行 pull 请求

git - 如何在 git push 后运行 bash 脚本

git - 如何在不从磁盘中删除文件的情况下 git rm 文件?

git - 无法推送到基于文件的存储库

git - 如何取消删除已删除的远程分支

git - 如何将 Ansible Git 安装到现有目录中

Github 使用 SSH key 提交

git - 来自远程存储库的快速 "git clone"?