Reputation: 33
Let's say I have the master branch and feature branches A, B, C, D and E.
C, D and E are merged into B, and B is merged into master.
They were all merged with --no-ff
at different times during development.
At one point the client decided he wants to drop features D and E.
I can go through the commit list and hand-pick the commits I want to revert, but that would take too much time and effort as there are possibly hundreds of them.
Is it possible to revert (in master or A) all commits originating just from branches D and E?
Upvotes: 3
Views: 37
Reputation: 52151
If you have two merged branches :
h : merge commit
|
v
---------*-* B
/
----* D
You can list the commits coming from D with the following command :
git rev-list h^..D
# h^ means : the first parent of h
# x..D means : any commit reachable from D and not reachable from x
You can first check visually that this list contains only commits you want to revert :
gitk h^..D # or gitg, or git log --oneline --graph ...
One of the numerous ways to undo this list of commits could be :
# example from branch A :
# create a working branch :
git checkout -b wip_removing_D
# revert the whole list of commits :
git revert --no-edit $(git rev-list h^..D)
# go back to the target branch :
git checkout A
# create a single commit which contains all of the reverts :
git merge --squash wip_removing_D
# delete working branch :
git branch -D wip_removing_D
Upvotes: 1
Reputation: 19035
You can do this by reverting the merge commits. Let's say D was merged into B at commit abc123
; in that case, do git revert -m 1 abc123
. Do the same for the commit where E was merged into B.
Note that if you want to reintroduce the changes from D and/or E in the future, you won't be able to just merge them in again; you will need to revert the commits created by the above git revert
commands. In other words, you'll need to "revert the revert".
Upvotes: 3