简体   繁体   中英

How can I find all the commits that have more than one parent in a Git repository?

I am working on a research to study merges in open source projects.

For each merge in the repo I need to find the base (nearest common ancestor), the two contributors, and the resulting merged commit.

I already have an idea of how to get the nearest common ancestor ( git merge-base rev1 rev2 ) and the contributors ( git log --pretty=%P -n 1 <commit> ), but I am having problem identifying the commits that resulted from a merge operation.

How can I find all the commits that have more than one parent in a Git repository?

This should be enough (for local commit)

 git rev-list --merges

The git rev-list man page mentions:

--merges

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

That means rev-list has some interesting filters:

--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 .

Try:

git log --merges

with the appropriate --pretty to parse the output.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM