Changes between Version 10 and Version 11 of GitCreateBundle


Ignore:
Timestamp:
Oct 23, 2013, 4:08:16 PM (11 years ago)
Author:
Piero Campalani
Comment:

add section on reverting merges

Legend:

Unmodified
Added
Removed
Modified
  • GitCreateBundle

    v10 v11  
    232232...and now you can proceed with the [wiki:GitCreateBundle#Creatingandsubmittingabundle bundle].
    233233
     234== I don't see any merge commit ==
     235
     236..you probably either forgot to add the `--no-ff` option when calling the merge (by default, but only if the merge is fast-forward, a normal single-parent commit is created), or somehow your .git/MERGE_HEAD passed away.
     237
     238This means you have your merge commit with lots of conflicts fixed that you want to re-apply.
     239One idea is to:
     240
     241   * save your merge to a patch, say `MERGE.patch`
     242   * reset to a pre-merge state and re-merge
     243   * if you have conflicts, just git-add everything to make git think you solved them, then commit
     244   * revert the (fake) commit and format a patch out of it, say `REVERT.patch`
     245   * reset again to a pre-merge state and again re-merge
     246   * re-git-add everything to mark conflicts solved (even though they aren't), but don't commit this time
     247   * apply `REVERT.patch` then `MERGE.patch` in the index
     248   * the two patches are applied, now you can git-commit.
     249
     250Let's say you applied a merge `M` of `feature_X` into `master`, but you see no merge commit in your history:
     251
     252{{{
     253  o-------A--------------M  master
     254           \           
     255            C----------D  feature_X
     256}}}
     257
     258{{{
     259#!sh
     260# Patch your merge commit:
     261$ git branch
     262* master
     263  feature_X
     264$ git format-patch HEAD~
     265MERGE.patch
     266
     267# Re-merge
     268$ git reset --hard A
     269$ git merge --no-ff feature_X
     270...
     271Automatic merge failed; fix conflicts and then commit the result.
     272
     273# Mark conflicts as solved, without applying changes
     274$ git add folder1/ folder2/ ...
     275$ git commit
     276# let's call it M'
     277
     278# Revert your fake merge
     279$ git revert -m 1 M'
     280# let's call this commit rM'
     281
     282# Patch the reversion
     283$ git format-patch HEAD~
     284REVERT.patch
     285}}}
     286
     287Graphically, this is the current situation:
     288
     289{{{
     290  o-------A--------------M'----------rM'  master
     291           \            /
     292            C----------D  feature_X
     293}}}
     294
     295Now we roll-back to a pre-merge state again, then we merge, revert, and apply our initial patch: `(M'+rM'+M) = (M'-M'+M) = M`
     296
     297{{{
     298#!sh
     299# Re-merge
     300$ git reset --hard A
     301$ git merge --no-ff feature_X
     302...
     303Automatic merge failed; fix conflicts and then commit the result.
     304
     305# Mark conflicts as solved, without applying changes, but don't commit now
     306$ git add folder1/ folder2/ ...
     307# ... now we are @ M', without explicit commit
     308
     309# Apply rM' and M (without commiting)
     310$ git apply --index REVERT.patch
     311$ git apply --index MERGE.patch
     312}}}
     313
     314Finally, we have our original merge, with true conflicts solution, but as a merge commit:
     315
     316{{{
     317  o-------A--------------M  master
     318           \            /
     319            C----------D  feature_X
     320}}}
     321
     322
    234323== Further reading ==
    235324
     
    237326   * [http://stackoverflow.com/questions/3635952/how-to-use-git-bundle-for-keeping-development-in-sync How to use git-bundle for keeping development in sync]
    238327   * [http://stackoverflow.com/questions/2285699/git-how-to-create-patches-for-a-merge Git: How to create patches for a merge?]
     328   * [http://git-scm.com/2010/03/02/undoing-merges.html Undoing Merges]