I have a clone of a public git repository. Simplified, the commits (A-D) look like this:
+->D
|
A->B->C
Commits A and B are already in the public repo. I added commit C to the clone that includes significant coding standard changes as well as significant feature changes. I later decided that I wanted to add a commit D to the clone that corrects only the coding standard issues in commit B.
I'd like to reorder commit C to come after commit D, so that things look like this:
A->B->D->C
Because I've already made the coding standard changes in both commits, I'd like to tell git to accept commit C as-is with no merging. I haven't been able to figure out how to do this. Can anyone suggest the right approach?
I had thought that git-rebase with a merge strategy our "ours" would do the trick, but am not having luck with that.
git checkout C
git reset --soft D
git commit
should be sufficient. git reset --soft merely resets what git thinks the "current" commit is, without actually making any changes whatsoever. So your index and worktree will still be exactly how they were in C, and you can commit that without needing to make any further changes.
Note that nothing in these commands will cause any sort of merge or automatic conflict resolution to take place. This means that if there is any part of D that isn't already part of C, this will cause those changes of D to be effectively reverted. You've stated that that's not the case, that D merely contains bits of C, so that shouldn't be a problem.
I use SourceTree as the GUI for GIT Assuming commit C is the master branch
You get the A->B->D->E, where E is C without the changes in D.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With