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?
In my case, I backed up and then deleted the file that Git was complaining about, committed, then I was able to finally check out another branch.
I then replaced the file, copied back in the contents and continued as though nothing happened.
Try this
and try pull again
The first command stores your changes temporarily in the stash and removes them from the working directory.
The second command switches branches.
The third command restores the changes which you have stored in the stash (the
--index
option is useful to make sure that staged files are still staged).You can't merge with local modifications. Git protects you from losing potentially important changes.
You have three options:
Commit the change using
Stash it.
Stashing acts as a stack, where you can push changes, and you pop them in reverse order.
To stash, type
Do the merge, and then pull the stash:
Discard the local changes
using
git reset --hard
or
git checkout -t -f remote/branch
Or: Discard local changes for a specific file
using
git checkout filename
I tried the first answer:
git stash
with the highest score but the error message still popped up, and then I found this article to commit the changes instead of stash 'Reluctant Commit'and the error message disappeared finally:
1:
git add .
2:
git commit -m "this is an additional commit"
3:
git checkout the-other-file-name
then it worked. hope this answer helps.:)
So the situation that I ran into was the following:
except, right before that, was remote: so actually this:
What was happening was (I think, not 100% positive) the git post receive hook was starting to run and screwing up due to movement changes in the remote server repository, which in theory, shouldn't have been touched.
So what I ended up doing by tracing through the post-receive hook and finding this, was having to go to the remote repository on the server, and there was the change (which wasn't on my local repository, which, in fact, said that it matched, no changes, nothing to commit, up to date, etc.) So while on the local, there were no changes, on the server, I then did a
git checkout -- some/file.ext
and then the local and remote repositories actually matched and I could continue to work, and deploy. Not entirely sure how this situation occurred, though a couple dozen developers plus IT changes may had something to do with it.