为什么我总是需要在 git pull 上手动合并?
我是 git 的新用户,不知道如何解决这个问题。我有一些使用 SVN 的经验,并且正在遵循 SVN 的行为。
每当我从远程存储库拉取文件,并且我修改的文件也被远程修改时,就需要合并。我可以理解复杂更改的合并冲突,但我看到非常小的更改(例如不同函数中的一行更改)的合并冲突。据我记得,SVN可以自动合并大部分文件,并且只有在自动合并失败时才会将文件置于冲突状态。
对于git来说,似乎每次都会发生并强制打开git合并工具。有没有办法自动合并文件?我是否缺少一些默认情况下基本上将存储库置于冲突集中的设置?
I am a new user of git and can't figure out how to get around this. I have had some experience with SVN and am going by SVN behavior.
Any time I pull files from remote repository, and the file I have modified are also modified remotely, it needs merging. I can understand merge conflicts for complex changes, but I am seeing merge conflicts for very small (e.g. one line change in different functions) changes. As far as I remember, SVN could merge most of it automatically and will put the file in conflicted state only if automatic merge failed.
For git, it seems to be happening every time and forcing to open the git merge tool. Is there any way to automatically merge the files? Am I missing some setting that is basically putting the repository in conflicted set by default?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
造成这种情况的一个常见原因是行结尾不同。您是否与使用不同操作系统的其他人共享存储库? SVN 对行结尾进行了一些修改。另一方面,Git 完全按照默认情况逐字节存储文件。这意味着,当 Windows 用户保存带有 \r\n 行结尾的文件,而 Linux 用户保存带有 \n 换行符的文件时,每一行都会出现更改,如果有任何其他更改正在发生,则会在各处引起冲突。要更改处理行结尾的方式,请使用配置设置“core.autocrlf”。在使用不同操作系统的存储库中,我建议将 Linux 用户设置为“input”,将 Windows 用户设置为“true”:
或者
实际上,我会说始终在全局范围内使用这些设置。他们会帮你省去一些心痛。在 git-config 手册页上阅读有关 core.autocrlf 的更多信息,并注意如果如果您遇到这个问题,并且使用现有存储库打开 autocrlf,您可能会看到一些令人惊讶的行为,但这是可以解释的。
A common cause of this is differing line endings. Are you sharing a repo with someone else using a different OS? SVN does some munging of line endings. Git, on the other hand, stores files byte-for-byte exactly as they are by default. That means that when a Windows user saves a file with \r\n line endings and a Linux user saves the file with \n line feeds, every line appears changed, and if any other changes are in play, it causes conflicts everywhere. To change the way line endings are handled, use the configuration setting "core.autocrlf". In a repo where different OS's are in play, I recommend setting it to "input" for Linux users and "true" for Windows users:
or
Actually, I'd say just use these settings globally all the time. They'll save you some heartache. Read more about core.autocrlf on the git-config man page, and note that if you're suffering from this problem and you turn autocrlf on with an existing repository, you may see some startling behavior, but it can be explained.
从手册中:
问:您使用什么 Git 客户端? Git 命令行工具?或者其他什么?
问:另外,有问题的文件是 Linux 还是 Windows?或者他们来自不同的环境?
From the manual:
Q: What Git client are you using? The Git command line tool? Or something else?
Q: Also, are the files in question both Linux, or both Windows? Or are they from different environments?