Git - 由于主服务器本地更改而合并时出错 [英] Git - error while merging because of local changes in master

查看:152
本文介绍了Git - 由于主服务器本地更改而合并时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(在topicBranch中)

  git add。 
git commit -m增加了新功能
git checkout master
git merger topicBranch

给了我以下错误:


错误:对以下文件的本地更改将被merge覆盖: / p>

查看日志,该文件只是一些与我的 xcuserdata 目录。我的想法是运行 git rm --cached path / to / that / file ,有问题的文件将从索引中删除,并且git对合并没有任何问题。但它仍然失败。



我的问题是A)如何让合并运行? B)鉴于git使用索引作为其主要兴趣领域,为什么不从索引中删除有问题的文件允许合并?

解决方案

您不应该从索引中删除该文件,而应将其重置或存储(即删除本地更改:文件在索引中仍然需要):

  git存储
#或
git checkout - 您的/ file#覆盖任何本地变更
#或核选项
git reset --hard



b
$ b

如果隐藏,正常的工作流程是



(来源:快速提示:利用Git Stash的威力


(in topicBranch)

git add .
git commit -m "added new feature"
git checkout master
git merger topicBranch

gives me the following error:

error: Your local changes to the following files would be overwritten by merge:

Looking at the log, the file in question is just some breakpoint related file buried deeply within my xcuserdata directory. My thinking was to run git rm --cached path/to/that/file and the problematic file would be removed from the index and git would have no problems with a merge. But it still fails.

My questions are A) how can I get the merge to run? B) given that git uses the "index" as its main area of interest, why wouldn't removing the problematic file from the index allow for a merge?

解决方案

You should not remove that file from the index, but reset it or stash it (meaning remove the local changes: the file is still needed in the index):

git stash
# or
git checkout -- your/file # overwrite any local change
# or, nuclear option
git reset --hard


If stashed, the normal workflow is to git stash pop after the merge.
(I actually prefer pull.rebase + rebase.autostash, that way git does stash for me on git pull)

Uncommited changes that are stored in the stash can be taken out and applied to the original branch and other branches as well.

(source: "Git Beginners Guide: Switching branches")

This is where the git stash command comes into play. Like git reset --hard, it gives you a clean working directory, but it also records your incomplete changes internally.
After fixing the critical bug, you can re-apply these changes and pick up where you left off. You can think of git stash as a "pause button" for your in-progress work.

(source: "Quick Tip: Leveraging the Power of Git Stash")

这篇关于Git - 由于主服务器本地更改而合并时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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