I want to rebase my branch (branch) on master (main). commit m1 means I have added a comment with the string m1 to the file. m2, b1 and so on are the same. What I do is:
git checkout branch
gitk --all
git rebase main
First, rewinding head to replay your work on top of it... Applying: b1 Using index info to reconstruct a base tree... M HelloWorld.java Falling back to patching base and 3-way merge... Auto-merging HelloWorld.java CONFLICT (content): Merge conflict in HelloWorld.java error: Failed to merge in the changes. Patch failed at 0001 b1 hint: Use 'git am --show-current-patch' to see the failed patch Resolve all conflicts manually, mark them as resolved with "git add/rm <conflicted_files>", then run "git rebase --continue". You can instead skip this commit: run "git rebase --skip". To abort and get back to the state before "git rebase", run "git rebase --abort".
#I fix the conflicts and add the file.
git rebase --continue
Applying: b1 Applying: b2 Using index info to reconstruct a base tree... M HelloWorld.java Falling back to patching base and 3-way merge... Auto-merging HelloWorld.java Applying: b3 Using index info to reconstruct a base tree... M HelloWorld.java Falling back to patching base and 3-way merge... Auto-merging HelloWorld.java Applying: b4 Using index info to reconstruct a base tree... M HelloWorld.java Falling back to patching base and 3-way merge... Auto-merging HelloWorld.java Applying: b5
git status
On branch branch Your branch and 'origin/branch' have diverged, and have 7 and 5 different commits each, respectively. (use "git pull" to merge the remote branch into yours) nothing to commit, working tree clean
gitk --all
I would like to know why it gets diverged and why the rebase do not work properly, what is causing it, and how can I fix it? am I doing the rebase wrong? When trying to figure out how to fix this issue, only thing I can find is how to go back to the first state (pic 1) with:
git fetch origin
git reset --hard origin/<branchname>

