I have master branch with initial state:
touch file
git add file
git commit -m "initial"
Then I did some changes:
echo "123" >> file
git commit -am "feature1"
which really belong to a feature branch, so I branched:
git branch TEST
and reverted change in master (I don't know if this is the best way to do it but it did what needed at the time):
git revert <last commit hash>
Then I did some more changes on feature branch:
git checkout TEST
echo "456" >> file
git commit -am "feature 1 continued"
And now I have problem merging master to it. What I want is to be able to merge all future changes in master to a TEST branch and keep my feature branch changes.
Code is already pushed to a remote.
Revert the revert
To be able to merge the
TESTbranch you'll need to revert the revert, so that theTESThistory can be applied cleanly.I.e. whereas originally the master branch history was:
And the
TESTbranch history is:What you'll need is to achieve this:
I.e. a checkout at
xxxxxxxand atzzzzzzzwould be exactly the same.Use an intermediary branch
To do that, a relatively easy way is to use an intermediary branch:
And then merge that branch with master:
This should result in a clean/consistent history in master, with the changes of
TESTcleanly applied.