I made some updates on my local machine, pushed them to a remote repository, and now I'm trying to pull the changes to the server and I get the message;
error: Your local changes to the following files would be overwritten by merge:
wp-content/w3tc-config/master.php
Please, commit your changes or stash them before you can merge.
So I ran git checkout -- wp-content/w3tc-config/master.php
and tried again and I get the same message. I'm assuming that w3tc changed something in the config file on the server. I don't care whether the local copy or remote copy goes on the server (I suppose the remote one is best), I just want to be able to merge the rest of my changes (plugin updates).
Any ideas?
This is probably being caused by CRLF issues.
See: Why should I use core.autocrlf=true in Git?
Use this to pull and force update:
Asking for commit before pull
If needed :
You can try one of the following methods:
rebase
For simple changes try rebasing on top of it while pulling the changes, e.g.
So it'll apply your current branch on top of the upstream branch after fetching.
This is equivalent to:
checkout master
,fetch
andrebase origin/master
git commands.checkout
If you don't care about your local changes, you can switch to other branch temporary (with force), and switch it back, e.g.
reset
If you don't care about your local changes, try to reset it to HEAD (original state), e.g.
If above won't help, it may be rules in your git normalization file (
.gitattributes
) so it's better to commit what it says. Or your file system doesn't support permissions, so you've to disablefilemode
in your git config.Related: How do I force "git pull" to overwrite local files?
WARNING: This will delete untracked files, so it's not a great answer to this question.
In my case, I didn't want to keep the files, so this worked for me:
Git 2.11 and newer:
Older Git:
Reference: http://www.kernel.org/pub/software/scm/git/docs/git-clean.html
-x means ignored files are also removed as well as files unknown to git.
-d means remove untracked directories in addition to untracked files.
-f is required to force it to run.