为什么我总是需要在 git pull 上手动合并?

发布于 2024-11-27 07:09:45 字数 274 浏览 0 评论 0原文

我是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

っ左 2024-12-04 07:09:45

造成这种情况的一个常见原因是行结尾不同。您是否与使用不同操作系统的其他人共享存储库? SVN 对行结尾进行了一些修改。另一方面,Git 完全按照默认情况逐字节存储文件。这意味着,当 Windows 用户保存带有 \r\n 行结尾的文件,而 Linux 用户保存带有 \n 换行符的文件时,每一行都会出现更改,如果有任何其他更改正在发生,则会在各处引起冲突。要更改处理行结尾的方式,请使用配置设置“core.autocrlf”。在使用不同操作系统的存储库中,我建议将 Linux 用户设置为“input”,将 Windows 用户设置为“true”:

git config [--global] core.autocrlf input

或者

git config [--global] core.autocrlf 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:

git config [--global] core.autocrlf input

or

git config [--global] core.autocrlf true

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.

埋葬我深情 2024-12-04 07:09:45

从手册中:

https://book .git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging

git 提交-a

此时两个分支已经分叉,有不同的变化
在每一个中制作。要将实验中所做的更改合并到主版本中,
运行

git 合并实验

如果更改不冲突,则完成。如果有冲突,
有问题的文件中将留下显示冲突的标记;

git 差异

将显示这一点。编辑文件以解决冲突后,

git 提交-a

将提交合并的结果。最后,

gitk

将显示结果历史的漂亮图形表示。

问:您使用什么 Git 客户端? Git 命令行工具?或者其他什么?

问:另外,有问题的文件是 Linux 还是 Windows?或者他们来自不同的环境?

From the manual:

https://book.git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging

git commit -a

At this point the two branches have diverged, with different changes
made in each. To merge the changes made in experimental into master,
run

git merge experimental

If the changes don't conflict, you're done. If there are conflicts,
markers will be left in the problematic files showing the conflict;

git diff

will show this. Once you've edited the files to resolve the conflicts,

git commit -a

will commit the result of the merge. Finally,

gitk

will show a nice graphical representation of the resulting history.

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文