I have two branches: master and experiment. Both of them evolved separately and are very different now. Now I am ready to make experiment branch my master branch.
If I try
git checkout master
git merge experiment
I get tons and tons of error.
What is the easiest way to get experiment branch to become master without loosing all the history of experiment branch.
I have already created a backup of m开发者_运维技巧aster branch as release 1.0 like this
git checkout master
git checkout -b release_1
Assuming these are private branches (i.e. nobody else is working on them), you can just set master
to experiment
like this:
git checkout master
git reset --hard experiment
If these are public branches, you'll probably want to merge and resolve conflicts, as Jefromi explains.
There are a few possibilities here, depending on exactly what you mean by "replace". You almost certainly took the right approach to start with - merging is generally the way to go. The "errors" you saw were merge conflicts, presumably. If you know for sure that, whenever there's a conflict, you want to use the version from your experimental branch, you could do:
# resolve conflicts by taking the version from experimental
# non-conflicting content is merged normally
git checkout master
git merge -Xtheirs experimental
If you want to use the version in experimental for everything, not just where there are conflicts, there are a ton of ways (there's not actually a merge strategy for this). The simplest:
# do the merge the other way around
git checkout experimental
git merge -s ours master
git checkout master
git merge experimental
# do the merge the right way
git checkout master
git merge --no-commit experimental # merge, but stop before committing
git checkout experimental . # check out content, but don't switch branch
git commit # commit the merge
The ways others have suggested (reset --hard
, branch -M
) will work, sort of, but since they don't create a merge commit, your master branch moves in a non-fast-forward way, potentially causing headaches for others who need to pull from this repo. Generally, I'd say that's the right answer only if these branches are unpublished.
You can rename your branch (from experiment):
git branch -M master
精彩评论