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

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更改了服务器上配置文件中的一些内容。我不关心本地副本或远程副本是否在服务器上(我认为远程副本是最好的),我只是希望能够合并我的其余更改(插件更新)。

什么好主意吗?


当前回答

我遇到的情况是这样的:

错误:您对以下文件的本地更改将被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 stash
git pull <remote name> <remote branch name> (or) switch branch
git stash apply --index

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

第二个命令切换分支。

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

在拉之前要求提交

git stash git pull pull origin << branch >

如有需要:

Git stash应用

要在解决此问题时记录新创建的文件:

如果你有新创建的文件,你可以创建一个本地更改的补丁,拉入远程合并,并在远程合并完成后应用你的本地补丁,如下所示:

进行本地更改。(不要承诺)。为新创建的文件创建补丁需要分段(因为它们仍然无法跟踪)

转到添加 。

创建一个补丁来保存记录

Git diff——缓存> myppatch .patch

丢弃本地更改并删除新的本地文件

Git重置——很难

把变化

git pull

应用补丁

去应用mypatch.patch

Git将合并更改,并为未合并的更改创建.rej文件。

根据Anu的建议,如果你在应用补丁时有问题,试试:

Git apply——reject——whitespace=fix myppatch .patch 本回答git: patch does not apply详细讨论了这个问题

享受您在特性上的持续工作,完成后提交您的局部更改。

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

转到添加 。

然后;

Git commit -m "your message"

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

如果你正在使用Git扩展,你应该能够在工作目录中找到你的本地更改,如下所示:

如果您没有看到任何变化,可能是因为您在错误的子模块上。所以检查所有的项目与潜艇图标如下所示:

当你发现一些未提交的更改:

选择带有工作目录的行,导航到Diff选项卡,右键单击带有铅笔(或+或-)图标的行,选择重置以第一次提交或提交或隐藏或任何你想做的事情。