I did the whole thing in VSCode version control.
I have two branches, a main and b1 branch. b1 branch came from main branch. After doing some commits on b1, I merged it back into main, but main already got some conflicting commits with that merge. I resolved the conflicts then finished the merge.
I did an undo commit after that. VSCode allows me to then do more changes then press commit again, finishing the merge. This created a simple commit, not the desired merge commit in main branch.
The problem is that many commits happened since then. I want to make this commit be a merge commit.
How could I solve this problem?
An example of the problem is here: https://github.com/KijeviGombooc/merge_test
3
Answers
How I solved the issue:
You need to play hardball every once in a while:
And now you can force-push into the remote with the new shiny
master
branch.Thanks for a clear example repo, it made it trivial to answer this question.
NB All the following command assume that everything is checked in and no files are modified at the start.
Step 0
Start using
gitk --all
as your every-day version history visualization tool from today and the rest of your life. Neither vscode nor any other IDEs have anything that is remotely close to as useful as gitk.Step 1
So you you have this
but would rather have this?
No problem.
Steps for the initial code setup:
which gives
(no code changes yet).
Step 2
Create a real merge commit.
Using KDiff3 the conflict was resolved the same way as the existing commit Merge branch ‘b1’:
which gives the following result:
Step 3
Now the only remaining part is to include the changes made after old-not-really-merge:
At this point
new_master2
is the result you asked for. It is a good idea to verify that the new branch is not fundamentally different:In this case there was a difference in line ending on the last line because you and I resolved the merge conflict slightly differently. You have to judge if changes like that are ok or not.
Step 4
After you have verified that
new_master2
is what you wanted you can reset the originalmaster
branch to the new branch:which then should give the same result as the second screenshot1.
At the end now I notice that the merge commit references the branch name
new_branch1
so a better approach would have been to start with renamingmaster
tomaster.old
and then use the namemaster
instead ofnew_branch1
. I’m not redoing commands and screenshots to fix that.1 I obviously did not push back to your
origin
repo, so the screenshot was taken from a "second level" local clone made withgit clone merge_test merge_test2
which then has my first merge_test repo as itsorigin
.