为什么git不会自动将无冲突的更改合并到本地修改的文件中? [英] Why doesn't git merge the conflict-free changes automatically into locally modified files?

查看:984
本文介绍了为什么git不会自动将无冲突的更改合并到本地修改的文件中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 对以下文件的本地更改将被合并覆盖:
app / Ribbon.xaml
请在提交更改或隐藏它们之前合并

在这个特定的情况下,我已经一行修改在此文件在本地,并在存储库中的新版本也一个遥远线改变 - 有没有冲突,没有重命名,行结尾没有变化,没有子模块。因此,在这种情况下,我希望git自动合并更改,而不要求我 git commit 或 git stash .. 。
我知道git能够自动合并更改(通常是这样做),但在这种情况下不能。



问题:什么可能会阻止git自动合并无冲突的更改(到本地修改的文件中)?

我猜,我的问题可能会遗漏一些数据。如果是这样,让我知道还有什么应该检查。



[27.JUN.2012 14:15]根据回答中的提示,git拒绝将任何更改合并到本地修改的文件是正常的策略。考虑到这一点,我会将这个问题改为类似于 ??方案

Git使用它的存储库中的项目根目录下的.git /目录中的文件。



Git使用此存储库进行比较当你进行pull和合并时。



在你的情况下,Git足够聪明地注意到你已经做了修改,但没有添加或提交它们,因此git将无法对他们的工作。



您得到的消息,请即使变化是单独的代码区因为你没有实际添加的文件以便git,git实际上并不知道是否会有冲突......直到git看到文件。如果你是 git add 然后是 git commit 这个文件,所以它在版本库中,然后git可以'工作'它,如果变化是在不同的区域这将是能够做到这一点自动合并你想看看。



所以,它给。该消息



您选项:




  • 添加和提交本地文件,然后git可以进行合并。

  • 隐藏本地更改以将它们保存在一边,然后拉出新的服务器文件。


  • 与当前更改创建分支 - 使用结帐,然后切换回主站和使用复位


$ b。 $ b

Doing git pull periodically I notice the command sometimes ends with the error like

Your local changes to the following files would be overwritten by merge:  
app/Ribbon.xaml  
Please, commit your changes or stash them before you can merge

In this particular case I have one line modified in this file locally, and its new version in the repository has also one faraway line changed - there are no conflicts, no renaming, no changes in line endings, no submodules. So in this case I would expect git to merge the changes automatically without requiring me to git commit or git stash...
I know that git is able to merge changes automatically (it does this usually), but not in this case.

And the question: what may prevent git from merging the conflict-free changes automatically (into locally modified files)?

I guess, some data may be missed in my question. If so, let me know what else should be checked.


[27.JUN.2012 14:15] According to the hints in the answers, it is the normal policy of git to refuse merging any changes into locally modified files. Taking this into account I would rephrase the question to something like how to enable git to merge the changes into locally modified files automatically?

解决方案

Git works on files in it's repository, under the .git/ directory at the root of the project.

Git uses this repository for comparison when doing pulls and merges.

In your case, Git is smart enough to notice that you have made changes, but not added or committed them and thus git would not be able to work on them.

You get the message, even though the changes are in separate areas of code because you have not actually added the file to git yet and git doesn't actually know if there will be a conflict... until git 'sees' the file. If you git add and then git commit the file, so it is in the repository then git can 'work' on it and if the changes are in separate areas it'll be able to do that automatic merge you were looking to see.

So it gives that message.

Your options are:

  • Add and Commit the local files, then git can do Merges.

  • Stash the local changes to save them aside and then Pull the new server files.

  • Create a branch with your current changes - use checkout, then switch back to master and use reset.

这篇关于为什么git不会自动将无冲突的更改合并到本地修改的文件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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