Question

What will happen in the following scenario:

  • There is a master branch with endless lifeline
  • New branches are created for features and merged with master when finished. The branch is afterwords deleted

At some point i needed to do a change in the feature that was already considered closed (it was merged into master and deleted)

      X --- --- (feature (branch deleted)
     /         \                
    /           \              
   a --- --- --- M master

What I did was:

git rebase --interactive X

Did the changes in the source and amended the commit X. I was hoping to have the graph unchanged but got something like:

        X --- -(feature (branch deleted)
       /      \
      /        M
     /        /
    /        /                 
   a --- --- --- X master

Does the editing of commits spread between merges? What about potential conflicts with existing "future" commits?

Was it helpful?

Solution

Your new commit graph has another X commit because rebase does not preserve merges by default. If you wanted to preserve merges, you need to use the --preserve-merges flag, or -p for short:

git rebase -i -p <base-commit>

Note that preserving merges interactively does not work correctly when you reorder commits. It's OK to use them together otherwise:

The todo list presented by --preserve-merges --interactive does not represent the topology of the revision graph. Editing commits and rewording their commit messages should work fine, but attempts to reorder commits tend to produce counterintuitive results.

Also, are you sure that X was the base commit you wanted to use? If you wanted to amend X, I think you should have chosen a as the base instead:

git rebase -i -p a
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top