Interactive rebase merged branch

I am using git and I get to this state:

X --- Y --------- M1 -------- M2 (my-feature) / / / / / / a --- b --- c --- d --- e --- f (stable) 

This happens when we work on the "my-feature" branch for more than one day. M1 and M2 are merged from a stable branch into a characteristic branch. M1 and M2 may have joint conflicts that have been resolved. The whole idea of ​​merging a stable branch with a characteristic branch is to handle conflicts sooner rather than later.

As soon as the function is completed, we want to reset the function branch to one or two commits.

The problem is when we do an interactive rebase git, show us the same merge conflicts that we already solve when merging M1 and M2.

Is there a way to make git reuse the merge solution that we have already implemented in M1 and M2?

+8
source share
4 answers

If merge conflicts are identical, this is ideal for using git rerere , one of the most useful (albeit less well-known) commands in git. From the man pages:

In a workflow that uses relatively long-lived threads, the developer sometimes has to resolve the same conflicts again and again until the threads are executed (either merged with the release branch or sent and received by the upstream).

This team helps the developer in this process by recording the conflicting results of the automatic merge and the corresponding hand resolution results at the initial manual merge, and applying the previously recorded hand resolutions to their respective automatic merge results.

git rerere keeps track of the resolution of your conflicts and automatically applies them when the same conflict occurs in git merge , git rebase or git commit (when merging is completed). Scott Chacon has posted some great examples here, and the man page is also worth reading.

You can enable git rerere in merge and rebase by running this command:

 git config --global rerere.enabled true 

Remove the --global flag if you want the option to be enabled for only one repository.

+10
source
  git rebase --interactive --preserve-merges
+6
source

The explicit way to create a feature branch to a new feature-one-commit branch with a single commit:

 git checkout -b feature-one-commit \ "$(git commit-tree HEAD^{tree} -m "Commit message" -p master)" 
+2
source

You can always force it to use the -f flag

0
source

All Articles