git-flow: How to prevent some changes made at release branch from merging back to development

StackOverflow https://stackoverflow.com/questions/17272659

  •  01-06-2022
  •  | 
  •  

Pergunta

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?

Foi útil?

Solução

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

Outras dicas

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?

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top