2

I have a branch "mybranch" which was created from the master but it has not been updated for the last couple of months. I want to update "mybarch" from a specific commit of the master branch. I want to ignore anything additional which is in "mybarch" and keep it in sync with the specific commit of the master branch. How can I achieve this? I'm trying this, does this sound ok? This results into many conflicts whereas I want to accept what comes from the master.

git checkout mybranch
git merge --squash master <commit-id>
Pankaj
  • 3,512
  • 16
  • 49
  • 83
  • If the history of the branch doesn't matter you can `git checkout -B mybranch ` – Opal Nov 13 '17 at 21:32
  • @Opal This will create new branch if I'm not wrong but I want to update the existing branch – Pankaj Nov 13 '17 at 21:33
  • Yes, it will ;) That's why I mentioned history not being relevant. What about: `git merge --squash -X theirs ..` – Opal Nov 13 '17 at 21:44
  • @Opal Tried this but there seems to be another problem which I didn't notice earlier - suppose master has A+B and mybranch has A+C, after merge I will be getting A+B+C where I want mybranch is same as master which is A+B – Pankaj Nov 13 '17 at 23:27

1 Answers1

0

suppose master has A+B and mybranch has A+C, after merge I will be getting A+B+C where I want mybranch is same as master which is A+B

Then you can simulate the merge with one of the --theirs strategy:

git checkout -b tmp master
git merge -s ours mybranch           # ignoring all changes from mybranch
git checkout mybranch
git merge tmp                        # fast-forward to tmp HEAD
git branch -D tmp                    # deleting tmp
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250