Home > Software engineering >  Committing reverted and new changes to master branch
Committing reverted and new changes to master branch

Time:06-24

  • I had committed half of the implementation of my current project to master branch.
  • Then I created new feature branch from master branch to implement rest of the implementation of the project.
  • Since there was an urgent release I have reverted partial implementation from master branch while keeping those changes in my feature branch.
  • After reverting my changes, other developer has added new commits to master branch.
  • Now there are few new commits also available on master branch which are not available on my feature branch

How should I commit my changes to master branch now?

CodePudding user response:

You can also pull from the master branch for the changes made then merge and compare with your existing branch , sync and push back into master branch.

CodePudding user response:

Start a new temp branch from the point before the first of the half-implementation commits. Cherry pick each of the half-implementation commits from master onto this new temp branch. Now rebase your feature branch, starting where it split from master, onto the temp branch.

Now you will have something ready to merge into master.

Example: suppose we have

A B F1 F2 REVERT X Y Z (master)
         \
          F3 F4 (feature)

Then you would say

git switch --det B
git switch -c temp
git cherry-pick F1
git cherry-pick F2
git rebase --onto temp F2 feature

The result is

A B F1 F2 REVERT X Y Z (master)
   \      
    F1' F2' F3' F4' (feature)

Now feature consists of copies of F1 F2 F3 F4, expressing exactly the history of your feature, and it is ready to merge into master.

  • Related