【问题标题】:Every time a co-worker commits a merge in git, all 10k+ files in the project have their line endings changed每次同事在 git 中提交合并时,项目中所有 10k+ 文件的行尾都会更改
【发布时间】:2017-08-27 14:21:39
【问题描述】:

所以在我的工作场所,我们有许多员工混合使用 Windows 和 Linux 系统,Eclipse 是首选的官方 IDE。我个人使用的是 IntelliJ IDEA,但这并不真正相关......我们最近从 SVN 切换到了 Git。

我的一位同事正在与我一起进行一个项目,他现在至少 3 次设法在他进行合并然后推送到原点时意外更改了整个存储库中的所有行结尾。我不知道他是如何做到这一点的,但这显然与他解决合并冲突的过程有关。我们都使用 Windows,我们推送到的存储库位于 Linux 机器上。

我们都从https://git-scm.com/download/win 安装了 git,并选择了默认选项(afaik,正确处理行尾)...但是 Eclipse 中的 egit 可以以某种方式做一些不同的事情吗?

【问题讨论】:

  • 服务器的类型在这里无关紧要。对于 Git(我不能代表 Egit)来说,重要的是你告诉 Git 在结账和签入期间如何处理行尾,以及你是否要求使用 merge.renormalize 进行虚拟签出和签入。其他重要的变量是core.autocrlfcore.eol,以及.gitattributes 中的任何设置(尽管.gitattributes 会以同样的方式影响每个人)。而且,如果您的朋友正在使用任何外部 合并工具,那么该合并工具的作用将很重要(例如,可能 it 将所有内容强制为 crlf 或 lf-only)。
  • 检查您的两个.gitconfig 文件。寻找相同配置参数的不同值。

标签: eclipse git


【解决方案1】:

您要做的是在存储库的根目录中创建一个“.gitattributes”文件。此文件对于您的存储库是唯一的,如果其他协作者设置了 core.autocrlf 或 core.eol,它将覆盖任何其他协作者 .gitconfig 设置。

# Set the default behavior, in case people don't have core.autocrlf set.
* text=auto

# Explicitly declare text files you want to always be normalized and converted
# to native line endings on checkout.
*.c text
*.h text

# Declare files that will always have CRLF line endings on checkout.
*.sln text eol=crlf

# Denote all files that are truly binary and should not be modified.
*.png binary
*.jpg binary 

以上是来自here. 的示例 .gitattributes 文件,当然这必须根据您的需要进行配置。

以下是更新存储库的步骤,同样来自here.

git add . -u
git commit -m "Saving files before refreshing line endings"
rm .git/index
git reset
git add -u
git add .gitattributes
git commit -m "Normalize all the line endings"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-21
    • 2020-08-13
    • 1970-01-01
    • 2012-03-03
    • 1970-01-01
    • 2018-06-29
    相关资源
    最近更新 更多