Search code examples
gitrevert

Can I create new branch from commits prior to merge


I have three branches:

  • master
  • frontend-updates
  • new-checkout

A developer made a number of commits in frontend-updates that were ready to be merged into master. However, before merging into master he merged new-checkout into frontend-updates and pushed them to our origin repo.

I need to merge all commits to frontend-updates (that occurred prior to the new-checkout merge) into master. I suppose I could cherry-pick each commit, right? But that seems painful. The next option I know if is git revert but I am not familiar with reverting and do not want to make the revert permanent. Eventually, we will want the new-checkout commits in master, just not yet.


Solution

  • The changes will still exist in the new-checkout branch, as long as the branch itself exists. You can revert to the commit immediately before the merge of the new-checkout branch into frontend-updates.

    Once that's done, merge frontend-updates into master and you're done. You can always remerge the new-checkout branch whenever you need to. The revert would not be permanent, as such.