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

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

什么好主意吗?


当前回答

如果只有一个文件在本地更新,并且您想要丢弃该文件中的更改,那么您可以执行以下操作——

// Pull latest activities-page.tsx from remote and discard local changes.
git checkout activities-page.tsx  
//Pull latest branch
git pull origin master

其他回答

我遇到的情况是这样的:

错误:您对以下文件的本地更改将被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.

这解决了我的错误:

我在分支A上

git stash

移动到主分支:

git checkout master 
git pull*

回到我的分支,A

git checkout A 
git stash pop*
git stash
git pull <remote name> <remote branch name> (or) switch branch
git stash apply --index

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

第二个命令切换分支。

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

我尝试了第一个答案:得分最高的git stash,但错误消息仍然弹出,然后我找到了这篇文章来提交更改,而不是stash“勉强提交”

错误信息最终消失了:

1:去添加.

2: git commit -m "这是一个额外的提交"

3: git checkout the-other-file-name

然后就成功了。希望这个答案能有所帮助。

在我的NestJS项目中,我在.env文件中遇到了类似的问题。

尝试了很多方法,包括本页上的方法。

最后,在剪贴板上复制。env的内容,删除文件,git拉起工作!

重新创建.env并将内容粘贴回来。

如果有多个文件,只需将它们临时移出git回购目录,然后在拉出更改后将它们移回。