The question is about some edge case of git-flow methodology
I have some kind of typical git-flow history like this:
o---o---o---o [release-3.5.0]
/
----o---o---o---o---o [development]
Git-flow told us to merge release-3.5.0 branch into development then release is ready. So, eventually we'll get ALL changes, made at release branch into development branch.
o---o---o---o
/ \
----o---o---o---o---o [development]
Now imagine, we have a commit 'X' on release branch what we DO NOT want at development branch, for example it is some kind of hack/hotfix or else which is already fixed in development in more sane way (i.e. by commit Y)
o---X---o---o [release-3.5.0]
/
----o---o---o---Y---o [development]
So, the main question is how to deal with such situations? How to prevent this commit (or commits) from getting back into development?
While the answers recommending rebase
and/or merge/revert/squash will work, I personally think the better answer would be this:
git checkout development
git merge --no-commit release-3.5.0
# make whatever changes you need to fixup the "hack" and/or clean up any conflicts
git commit
In such scenarios you always want to fully merge the release(-like) branches. So make sure nothing is missing.
But during the merge you can freely modify the content -- including to drop or redo some changes. For your example case, merge the branch, revert the commit you don't like, and squash that revert into the merge commit. Obviously make a note in the merge commit message of that action.
If the fix is already on devel, merge will just skip over it, or you resolve the conflict by selecting the devel version.
The point is you want the history show as your second figure, and the state as it makes best sense.
You have several options :
1) use git rebase -i
In this mode you can rebase your release branch on your development branch and exclude the Xth commit.
Warning You will mess the existing cloned repositories in this case.
2) use git cherry-pick
In this mode you will have the possibility to pick commits one by one.
3) use git rebase -i
on a separate branch and merge it afterwards, as specified in this answer : Is it possible to exclude specific commits when doing a git merge?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With