If I checkout a branch a
from main branch, and I have made many changes on a
branch. But the main branch revert some commits for some reasons. How can I merge a
branch's changes to main branch the right way?
CodePudding user response:
Ideally, you would git cherry-pick
from main
the revert commits done on main
, to apply the same revert on a
.
git switch a
git cherry-pick <commitSHA1-from-main> # a commit representing a revert
Then you can make a regular merge from a to main
.
CodePudding user response:
You can use git rebase in interactive modes and remove the undone commits.
git checkout master
git pull
git checkout a
git rebase -i master
Remove the deleted commits in the following view with d and then save them.
d 38608aa remove commit from master
d f23afss remove commit from master
pick 183b5fg first commit from a
pick fasde6e second commit from a
After that, you can merge branch a to master.