Last active
March 13, 2019 20:11
-
-
Save JonathanGawrych/e250e645f5f21f8687c52dc218a4ac23 to your computer and use it in GitHub Desktop.
Force a remerge using git's plumbings commands
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # If remerging a revert, do this to get back your changes | |
| git revert revertSha | |
| git reset HEAD~ | |
| git add -A | |
| # And skip to the echo below | |
| # Find the merge-base of an already merged branch | |
| # https://stackoverflow.com/a/4991675/1248889 | |
| diff -u <(git rev-list --first-parent topic) <(git rev-list --first-parent develop) | sed -ne 's/^ //p' | head -1 | |
| # Performs merge into the cache | |
| # Use the merge_base from above | |
| # If getting an error about overwritting the current tree, do `git read-tree --empty` first | |
| # Attempted --aggressive if your merge has too many non-conflict conflicts | |
| git read-tree -u -m merge_base^{tree} develop^{tree} topic^{tree} | |
| # Resolve merge conflicts. | |
| git mergetool | |
| # Note if there is "deleted by us", you can resolve all of those to 'keep deleted' by running: | |
| # https://stackoverflow.com/questions/45322360/#comment94060841_45322637 | |
| git status --porcelain | grep "DU" | cut -c4- | xargs git rm | |
| # Creates a commit using the cache with parents being the current branch and the merged branch | |
| echo "Remerge branch 'topic' into 'develop'" | git commit-tree $(git write-tree) -p develop -p topic | |
| # Resets this branch to the above commit | |
| git reset --hard ABOVE_COMMAND_HASH_OUTPUT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment