我在本地机器上做了一些更新,将它们推送到远程存储库,现在我试图将更改拉到服务器上,我得到了消息;

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.

所以我跑了,

git checkout -- wp-content/w3tc-config/master.php

再试一次,我得到了同样的信息。我假设w3tc更改了服务器上配置文件中的一些内容。我不关心本地副本或远程副本是否在服务器上(我认为远程副本是最好的),我只是希望能够合并我的其余更改(插件更新)。

什么好主意吗?


当前回答

对我来说,只有重新开始,努力工作。

承诺不是一个选项,因为没有什么可承诺的。

藏东西是不可能的,因为没有东西可以藏。

看起来它可能来自。git/info/exclude中的排除文件,并且git update-index——assume-unchanged <file>'ed了一些文件。

其他回答

您可以尝试以下方法之一:

变基

对于简单的更改,尝试在它的基础上重新调整,同时拖动更改,例如。

git pull origin master -r

所以它会在取回后把你当前的分支应用到上游的分支上。

这相当于:checkout master, fetch和rebase origin/master git命令。

这是一种潜在危险的操作方式。它重写了历史,这不是一个好兆头,因为你已经出版了那段历史。除非你仔细阅读了git-rebase(1),否则不要使用这个选项。


结帐

如果你不关心你的局部变化,你可以暂时切换到其他分支(强制),然后切换回来,例如。

git checkout origin/master -f
git checkout master -f

重置

如果您不关心您的本地更改,尝试将其重置为HEAD(原始状态),例如。

git reset HEAD --hard

如果上面没有帮助,它可能是你的git规范化文件(.gitattributes)中的规则,所以最好提交它所说的。或者你的文件系统不支持权限,所以你必须在git配置中禁用filemode。

相关:我如何强制“git拉”覆盖本地文件?

git stash
git pull <remote name> <remote branch name> (or) switch branch
git stash apply --index

第一个命令将更改临时存储在存储区中,并从工作目录中删除它们。

第二个命令切换分支。

第三个命令恢复您在stash中存储的更改(——index选项用于确保暂存文件仍然是暂存的)。

如果你在你的任何文件做了更改;

转到添加 。

然后;

Git commit -m "your message"

在此之后,你可以成功地从你的回购中获取或推入。

我遇到的情况是这样的:

错误:您对以下文件的本地更改将被merge覆盖: wp-content / w3tc-config / master.php 请在合并之前提交您的更改或隐藏它们。

除了,在那之前,是遥远的: 实际上是这样的:

您对以下文件的本地更改将被merge覆盖: 一些/ file.ext 请在合并之前提交您的更改或隐藏它们。

发生的事情是(我认为,不是100%肯定)git post receive钩子开始运行,由于远程服务器存储库中的移动变化而搞砸了,理论上,不应该触及。

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.

使用:

Git重置——很难

然后:

Git拉源主