从Git远程服务器拉出时,使用远程更改解决冲突 [英] Resolve conflicts using remote changes when pulling from Git remote

查看:293
本文介绍了从Git远程服务器拉出时,使用远程更改解决冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从我的GitHub仓库中将代码拖到我的服务器上,但由于合并冲突,拖动仍然失败。我不想保留自上次拉取以来本地服务器上可能发生的任何更改。

I'm trying to pull code from my GitHub repo onto my server, but the pull keeps failing because of merge conflicts. I don't want to keep any of the changes that may have occurred on my local server since the last pull.

那么是否有办法强制Git覆盖与GitHub中的任何版本,而不是打扰我冲突?

So is there a way I can force Git to overwrite with whatever version is in GitHub, rather than bother me about conflicts?

推荐答案

如果你真的想要放弃你在本地创建的提交,即再也不会在历史记录中提交它们,你不会问如​​何拉 - 拉合并,你不需要合并。所有你需要做的就是这样:
$ b

If you truly want to discard the commits you've made locally, i.e. never have them in the history again, you're not asking how to pull - pull means merge, and you don't need to merge. All you need do is this:

# fetch from the default remote, origin
git fetch
# reset your current branch (master) to origin's master
git reset --hard origin/master

我个人建议先在当前的HEAD上创建一个备份分支,这样如果您意识到这是一个糟糕的主意,那么您还没有失去它的踪迹。

I'd personally recommend creating a backup branch at your current HEAD first, so that if you realize this was a bad idea, you haven't lost track of it.

另一方面,如果您想要保留这些提交并使其看起来好像与源合并,并使合并仅保留来自版本的版本,则可以使用我们的合并策略:
$ b

If on the other hand, you want to keep those commits and make it look as though you merged with origin, and cause the merge to keep the versions from origin only, you can use the ours merge strategy:

# fetch from the default remote, origin
git fetch
# create a branch at your current master
git branch old-master
# reset to origin's master
git reset --hard origin/master
# merge your old master, keeping "our" (origin/master's) content
git merge -s ours old-master

这篇关于从Git远程服务器拉出时,使用远程更改解决冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆