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

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重置——很难

其他回答

丢弃局部更改 使用git重置——很难

使用:

Git重置——很难

然后:

Git拉源主

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

错误信息最终消失了:

1:去添加.

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

3: git checkout the-other-file-name

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

在使用reset之前,请考虑使用revert,这样您就可以随时返回。

https://www.pixelstech.net/article/1549115148-git-reset-vs-git-revert

根据要求

来源:https://www.pixelstech.net/article/1549115148-git-reset-vs-git-revert

Git重置vs Git恢复 sonic0002 2019-02-02 08:26:39

When maintaining code using version control systems such as git, it is unavoidable that we need to rollback some wrong commits either due to bugs or temp code revert. In this case, rookie developers would be very nervous because they may get lost on what they should do to rollback their changes without affecting others, but to veteran developers, this is their routine work and they can show you different ways of doing that. In this post, we will introduce two major ones used frequently by developers.

去重置 git 还原

它们的区别和对应的用例是什么?我们将在下面详细讨论它们。 git重置 假设我们有以下几个提交。

提交A和B是工作提交,但提交C和D是坏提交。现在我们想回滚提交B,并删除提交C和D。目前HEAD指向提交D 5lk4er,我们只需要指向HEAD提交B a0fvf8来实现我们想要的。 git reset命令的使用很简单。

git reset --hard a0fvf8

执行上述命令后,HEAD将指向提交B。

但是现在远程的原点仍然有HEAD点提交D,如果我们直接使用git push来推送更改,它不会更新远程repo,我们需要添加一个-f选项来强制推送更改。

git push -f

这种方法的缺点是,一旦重置完成,HEAD之后的所有提交都将消失。万一有一天我们发现有些提交吃了很好的,想要保留它们,那就太晚了。因此,许多公司禁止使用这种方法来回滚更改。

git恢复 git revert的用途是创建一个新的提交,该提交将恢复之前的提交。HEAD将指向新的还原提交。 对于上面的git重置的例子,我们需要做的只是还原提交D,然后还原提交C。

git revert 5lk4er
git revert 76sdeb

现在它创建了两个新的提交D'和C',

在上面的例子中,我们只有两个提交需要恢复,所以我们可以一个一个地恢复。但是如果有很多提交要恢复怎么办?我们可以还原一个范围。

git revert OLDER_COMMIT^..NEWER_COMMIT

这个方法不会有git重置的缺点,它会将HEAD指向新创建的还原提交,并且可以直接将更改推到远程而不使用-f选项。 现在让我们来看一个更难的例子。假设我们有三次提交,但错误的提交是第二次提交。

使用git reset回滚提交B不是一个好主意,因为我们需要保持提交C,因为它是一个好的提交。现在我们可以恢复提交C和B,然后再使用选择性提交C。

从上面的解释中,我们可以发现git reset和git revert之间最大的区别是git reset会通过删除提交后的所有更改来重置分支的状态到之前的状态,而git revert会通过创建新的恢复提交并保留原始提交来重置到之前的状态。建议在企业环境中使用git revert而不是git reset。 参考:https://kknews.cc/news/4najez2.html

我遇到的情况是这样的:

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