git rebase scenario analysis

git rebase

    --rebase

Will not generate merged commits, it will temporarily save all local commits as patches, put them in the ".git/rebase" directory, then update the current branch to the latest branch tip, and finally apply the saved patch To the branch.

During the rebase process, there may be conflicts. Git will stop the rebase and let you resolve the conflicts. After the conflicts are resolved, use git add to update the content, and then there is no need to execute the commit, just:

git rebase --continue will continue to apply the remaining patches.

git rebase --abort will terminate the rebase, and the current branch will return to the state before rebase. An

excerpt from the most complete guide to git
This explanation seems a bit complicated. Let me talk about the scenario of using rebase in the actual work process:
just When I started working, I was not familiar with the use of git. I pushed the code of my local branch when I git push, that is,
local branch:
master (main branch)
mybranch (own branch)

git push origin:mybranch
then reported your branch is 1 behind of "origin/master" error when submitting mr, (that is, my branch is behind the branch of the main warehouse), which
means I was before submitting my branch I didn’t pull the latest code of the main warehouse first, and I pushed it directly. I
tried to pull the local warehouse again, re-git add to the master, and then push. I found that the error was still not resolved
and I consulted others again and solved the problem. , But I didn’t quite understand it, so I went through the process again.
Step 1: Switch back to the master branch of the local warehouse and pull the latest code of the remote warehouse.
git branch
git checkout master
git pull origin master
Step 2: Switch back to yourself The branch, git rebase master, this step refers to patching all commits of the local master branch to the current branch, that is, synchronizing the commit records of the local master branch and your branch
git checkout yourbranch
git rebase master
Step 3: Mandatory Push the commit of your own branch to the remote warehouse
git push -f origin mybranch

Guess you like

Origin blog.csdn.net/qq_36875803/article/details/110593043