简体   繁体   中英

Squash master now need to merge another branch

I have two git branches, master and dev for a project. Yesterday I was learning how to use git rebase to interactive squash commits. I squashed my master branch and it now only contains only a few commits. Today I worked on my dev branch (I branched prior to squashing master ) and made a number of commits on this dev branch. Now, I would like to merge my dev branch back into my squashed master . It was foolish of me, but I realize this was the wrong thing to do.

How can I now merge my dev branch into a squashed master ? Is there any way to to do this?

I assume the commit you branched dev off of master was affected by the squash, otherwise there shouldn't be any "unnatural" merge conflicts.

There are two ways I can think of to do what you want without actually dealing with those merge conflicts:

  1. Undo the squashing you did on master . The pre-squash state of master is most likely still in your repository - use git reflog to find it and git reset to reset master to it. If you made additional commits on master after the squash, you can get them onto your restored master with git cherry-pick . This option might not be viable if you have already pushed the squashed master and other people are using it.

  2. git cherry-pick the additional commits you did on dev onto master , then delete the unmergeable dev branch. This option might not be viable if you have already pushed dev and other people are using it.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM