How to force a pull to a file in git?
I am 开发者_如何学运维having a merge conflict, and I can usually just rename the file and pull from the repo ti resolve or manually edit the edit. This time, I committed changes to a file that has conflicts, and it is in the staging area.
I tried using git reset HEAD <file>
and then using git pull
again, but I still get merge conflicts.
Is there a way to force the overwrite of the troublesome file?
Here is the message that I get: error: Your local changes to the following files would be overwritten by merge: db/profile_edit.php
I change the name of the file to profile_edit.phpbkup.
Then I do a git pull
And I still get the same error. Why is this? The file doesn't even exist anymore, so how can it be replaced?
Thanks.
if you want to throw away all changes you made concurrently to upstream:
git fetch origin
git push -f . origin/branchA:branchA
if you want to resolve conflicts favouring upstream instead:
git fetch origin
git merge -s recursive -Xtheirs origin/branchA
hope this helps.
You can get the file out of the index with git reset filename
, if you don't want those changes add the --hard
switch to the reset.
The conflicts themselves will need to be resolved.
One option is to git fetch remoteRepo
This will fetch the remote repo, but does not try and merge the branches together.
To diff the two versions of the file you are interested in, use git diff HEAD remoteRepo/remoteBranch <fileName>
If there are merge conflicts and you want to keep content from both files, there is nothing you can do but resolve the conflicts.
精彩评论