I have the following scenario:
M
|
|
o X
| /|
|/ |
a b
| /
|/
o
I checked out b
, then ran git merge a
. There were some conflicts which were resolved in the merge commit X
. I also did some misc changes within X
.
I want to squash X
and b
, and then rebase the squash on M
. The goal is to avoid re-doing the changes that were done to build X
.
(X+b)
|
|
M
|
|
o
|
|
a
|
|
o
Any ideas on how to do this?
You can:
# from X :
git reset --soft o # <- the parent commit of a and b
git commit # this will create 'b + X'
# then rebase :
git rebase M
You may have extra conflicts to fix when rebasing.
An alternative way can be:
M
and X
reset --soft + commit
to create a single commit# from commi M :
git merge X
# fix possible merge conflicts
git reset --soft M
git commit # commit the content of the merge
# as a single regular commit on top of M
Alternative method:
git checkout M
git merge --squash X
git commit -m "implemented feature X"
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.