解决合并冲突:强制覆盖所有文件 [英] Resolve merge conflicts: Force overwrite all files

查看:281
本文介绍了解决合并冲突:强制覆盖所有文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我自己在一个git仓库上工作(所以是的,我知道这样做的含义和警告),并且不知怎的,其中一棵树在被推动时得到了一个提交,现在我试图撤回,它抱怨数百个合并冲突。



有没有办法告诉git强行覆盖来自远程服务器的任何本地文件?有没有比做 git reset --hard HEAD〜1 然后做拉的更快的方法?



开同样的说明,有没有办法与简单的合并做同样的事情?我看到的所有东西都表明在合并冲突解决阶段检查每个文件,但有数百个文件,这是无法手动完成的。 解决方案

有三种简单的解决方案来复制远程存储库中的最新版本,放弃您在本地进行的所有更改:


  1. 放弃您的存储库并再次克隆。这是最简单的解决方案,但是如果您的存储库很大,则可能需要很长时间,并且可能需要额外的努力,例如重新配置 ing等。


  2. 使用 git reset --hard< hash> 放弃本地更改,然后执行 git pull 。问题是你需要首先在你试图避免的变化历史之前找到一个提交。重置为该提交哈希之后,执行 git pull


  3. 执行 git fetch 将更新引入远程分支的本地引用(通常是origin / master),然后执行 git reset --hard 通过这个引用,即 git reset --hard origin / master



I am working on a git repository by myself (so yes, I know the implications and the warnings of doing this) and somehow one of the trees got a commit after being pushed when it shouldn't have.

Now I'm trying to pull back and it's complaining about hundreds of merge conflicts.

Is there a way to tell git to forcefully overwrite any and all files locally that are coming from the remote server? Is there a faster way than doing git reset --hard HEAD~1 and then doing the pull?

On that same note, is there a way to do the same with with a simple merge? Everything I've seen suggests to check out each and every file during the merge conflict resolution stage, but with hundreds of files it's just not possible to do so manually.

解决方案

There are three simple solutions to copy the last version that is in you remote repository, discarding all changes that you have made locally:

  1. Discard your repository and clone again. This is the most simple solution, but if your repository is big, it can take a long time, and may require extra effort like reconfigureing, etc.

  2. Discard the local changes with git reset --hard <hash> and then do a git pull. The problem is you need to first find a commit that precedes whatever change history you are trying to avoid. After resetting to that commit hash, do a git pull.

  3. Do a git fetch to bring the updates to your local reference of the remote branch (usually origin/master) and then do a git reset --hard passing this reference, ie, git reset --hard origin/master.

这篇关于解决合并冲突:强制覆盖所有文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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