I have the following situation:
_____________G ..myBranch
/
/
S---B---C1---C2---C3---C..---C230 .. master
S=working version
B=bad version of task
G=good version of task
C=commit after B
and I would like to commit and merge the master into myBranch without using B and then merge myBranch into master with the new commits. Is something like that possible with merge/rebase/cherrypicks?
Thanks!
Yes. You can do:
git checkout mybranch
git rebase -i master
This will present you with a screen where you can choose which commits to include. Remove the line that has the commit B
, save, and close your editor.
See also: https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History
The git rebase answer should work, but if you're wondering how cherry-pick works, you can use use it instead, like this:
git checkout myBranch
git cherry-pick C1..master
This will create new commits in myBranch based on diffs of commits C1 to C230 in master (which is the same as what using rebase -i would do).
If you haven't already published master and you can just rewrite history, you can use git reset to update master:
git checkout master
git reset --hard myBranch
If you have published master , that is not advisable. Instead, you can merge master into myBranch using the ours strategy, and then merge master into myBranch :
git checkout myBranch
git merge -s ours master
git checkout master
git merge myBranch
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.