Reputation: 23022
Suppose I have a master
branch and a feature
branch. feature
is severely outdated and I now want to make it exactly like master
, but I want all changes made to feature
that were required in order to complete the "merge" to appear in a single commit.
First I tried this:
git checkout feature
git merge --squash master
But this gives me a squillion conflicts. I don't want to manually resolve conflicts, I want to simply take whatever is in master
and be done with it. So I do this:
git checkout feature
git merge --squash -X theirs master
With this I still get merge conflicts (where files were deleted in master
. What do I do now? I could do git reset --hard master
but then I don't get a commit message that shows the changes.
Any ideas? I'm using git 1.8.1.2
.
Upvotes: 1
Views: 52
Reputation: 487745
See the answers to git command for making one branch like another. Note that there's rarely any good reason to do this in the first place (as already noted as the first comment on that question).
There's another method for doing this, not listed there. This assumes you're in the top level directory of your repository:
git checkout feature
git merge --no-commit -s ours master # -s ours just to make things quiet
git rm -q -rf . # remove all resulting files
git checkout master -- . # replace with master branch version
git commit
In fact, you don't need the git merge
command at all; here's a variant without it:
git checkout feature
git rm -q -rf .; git checkout master -- .
git rev-parse master > .git/MERGE_HEAD
git commit
(the difference is that the last git commit
will give you a different starting message—using git merge --no-commit
leaves a MERGE_MSG
file in the git directory as well, to provide the commit message).
Upvotes: 1