行尾在 Git 中搞砸了 - 如何在巨大的行尾修复后跟踪另一个分支的更改? [英] Line endings messed up in Git - how to track changes from another branch after a huge line ending fix?

查看:23
本文介绍了行尾在 Git 中搞砸了 - 如何在巨大的行尾修复后跟踪另一个分支的更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用定期更新的 3rd 方 PHP 引擎.版本保存在 git 中的一个单独分支上,我们的 fork 是 master 分支.

We are working with a 3rd party PHP engine that gets regular updates. The releases are kept on a separate branch in git, and our fork is the master branch.

通过这种方式,我们将能够从新版本的引擎中将补丁应用到我们的分支.

This way we'll be able to apply patches to our fork from the new releases of the engine.

我的问题是,在对我们的分支进行多次提交后,我意识到引擎的初始导入是使用 CRLF 行结尾完成的.

My problem is, after many commits to our branch, I realized that the initial import of the engine was done with CRLF line endings.

我将每个文件都转换为 LF,但这做了一个巨大的提交,删除了 100k 行并添加了 100k 行,这显然破坏了我们的意图:轻松合并来自该 3rd 方引擎的工厂版本的补丁.

I converted every file to LF, but this made a huge commit, with 100k lines removed and 100k lines added, which obviously breaks what we intended to do: easily merge in patches from the factory releases of that 3rd party engine.

我怎么知道?我怎样才能解决这个问题?我的叉子上已经有数百次提交了.

What whould I do know? How can I fix this? I already have hundreds of commits on our fork.

最好的办法是在初始导入之后和分支我们自己的分支之前以某种方式做一个行尾修复提交,并在历史后期删除那个巨大的行尾提交.

What would be good is to somehow do a line endings fix commit after the initial import and before branching our own fork, and removing that huge line ending commit later in history.

但是我不知道如何在 Git 中做到这一点.

However I have no idea how to do this in Git.

谢谢!

推荐答案

我终于解决了.

答案是:

git filter-branch --tree-filter '~/Scripts/fix-line-endings.sh' -- --all

fix-line-endings.sh 包含:

fix-line-endings.sh contains:

#!/bin/sh
find . -type f -a ( -name '*.tpl' -o -name '*.php' -o -name '*.js' -o -name '*.css' -o -name '*.sh' -o -name '*.txt' -iname '*.html' ) | xargs fromdos

在所有提交的所有树中修复所有行结尾后,我进行了交互式 rebase 并删除了所有修复行结尾的提交.

After all line endings were fixed in all trees in all commits, I did an interactive rebase and removed all commits that were fixing line endings.

现在我的 repo 干净而新鲜,可以推送了 :)

Now my repo is clean and fresh, ready to be pushed :)

访问者注意:如果您的存储库已被推送/克隆,请不要这样做,因为它会将事情搞砸!

这篇关于行尾在 Git 中搞砸了 - 如何在巨大的行尾修复后跟踪另一个分支的更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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