Choose one origin as canonical for merge with git
I have a file that was modified in two different repositories and merged in my local repository after a pull. I know that one of the repositories is the actual version that I want, and don't want the merged version of the file. How can I tell git, after the merge has already been applied to开发者_运维技巧 the local version, to use one version or the other?
Remotes are just a way for git to fetch commits from somewhere. It's the commits that affect what version of content you see; it doesn't matter where they came from.
Picking a version of a file as "canonical" just means making sure that's the version of the file that's in the canonical repository. The upshot of that is that you probably want to do this in your local repository:
# make sure that origin is the canonical remote
# rename the other one to something else!
# make sure you're up to date
git fetch origin
# check out the desired version of the file
git checkout origin/master path/to/file
# and commit this modification
git commit
This could also be done as part of pulling from origin:
# pull from the default remote/branch, hopefully origin/master
git pull --no-commit
# get "their" (origin's) version
git checkout --theirs path/to/file
# commit the merge
git commit
The --no-commit
option tells git to stop before committing the merge which is part of the pull, so that you'll be able to modify the result of the merge then commit it. If there are conflicts (which may be likely in your case), then it would have stopped anyway to let you resolve them.
精彩评论