Cleaning master branch to version from another branch, but save progress to new temp branch

34 Views Asked by At

What is the best way to move all progress on the master branch from point X to a new temporary branch (e.g., new_master), rewind all changes to point X, and finally commit all changes from branch A as master.

This is what I have: existing_git

And what I want to achieve is:

  1. Move all changes from master, from "some changes" point to new branch.
  2. Merge all changes from 1.0.1.120 branch to master (but I must preserve pom.xml files from master)
2

There are 2 best solutions below

0
Dmitry On
  1. create your branch from commit hash (first commit message.)

     git checkout <sha1-of-commit (first commit message)>
     git checkout my-new-branch
    
  2. do your changes on your new branch as usual

Step 3 has variations, depending on what is easier:

3.1) do merge of master to your new branch with --no-commit option.

  • you will have all the files from master, and you can simply revert/remove changes that you don't want to have and then finally commit and merge back to master.

3.2) Save your pom files from master somewhere then merge master, without changes,e.g. keep your changes, and then manually add your saved pom files.:

git merge -s ours master # merge master but keep only my changes
0
Juan_m_2 On

You must do the following:

1. Move all changes from master, from "some changes" point to new branch

git branch new_master <sha1-of-commit (some changes)>

2. Merge all changes from 1.0.1.120 branch to master (but I must preserve pom.xml files from master)

git merge 1.0.1.120

You must be on master branch for this second command, assuming 1.0.1.120 hasn't changed your pom.xml file. If so, then do a merge without commiting:

git merge --no-commit 1.0.1.120

Then get your master branch pom.xml

git checkout master pom.xml

And finally commit

git commit