Search code examples
gitgit-rev-list

Git rev-list: exclude commits already included in a merge


I have a repository with a master branch that has frequent merges from different defect branches, like in the picture below (defect1 is the name of the defect branch):

I would like to retrieve a list of all the commits of the master branch, from the one previous to commit A up until the head (in this case, E). This list will be used to revert all the commits due to a specific use case of my project.

I've been gathering this list by using git rev-list:

git rev-list "${commitA}~1"..origin/master

The problem is that when I do that, I get commits X and Y in the mix, while commit D already includes the changes of both commits X and Y. I can revert commit D with git revert -m 1. When I try to revert X and Y I get an error, since the commits are not in the master tree. I would like to retrieve A~1, A, B, C, D and E only. I could easily do something like:

git rev-list "${commitA}~1"..origin/master ^defect1

but there can be multiple defect branches with different names and it's impossible to know their names in advance.

Are there other options within git-rev-list that can enable this behavior?


Solution

  • git rev-list master --first-parent