线结束在Git中搞砸了 - 如何在一个巨大的线结束修复后追踪另一个分支的变化? [英] Line endings messed up in Git - how to track changes from another branch after a huge line ending fix?

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

问题描述

我们正在与定期更新的第三方PHP引擎合作。这些版本保存在git中的一个单独的分支上,而我们的fork是master分支。



这样我们就可以将修补程序应用到我们的fork中发布引擎。

我的问题是,在我们分支的许多提交之后,我意识到引擎的最初导入是通过CRLF行尾来完成的。



我将每个文件转换为LF,但是这做了一个巨大的提交,删除了10万行并添加了10万行,这明显打破了我们打算做的事情:轻松地从该第三方引擎的工厂版本。



我该知道什么?我怎样才能解决这个问题?我们已经有数百次提交。



最好是在初始导入之后和分支我们自己的分支之前做一个行结束修复提交,以及删除那些结尾在历史后期提交的巨大行。



然而,我不知道如何在Git中执行此操作。



感谢!

解决方案

我终于设法解决了这个问题。 >答案是:

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

fix-line-endings.sh包含:

 #!/ bin / sh 
查找。 -type'* .tpl'-o -name'* .php'-o -name'* .js'-o -name'* .css'-o -name'* .sh '-o -name'* .txt'-iname'* .html'\)| xargs fromdos

在所有提交的所有树中所有行结束都已修复后,我进行了交互式变形,

现在我的回购很干净新鲜,准备推出:



访问者注意:如果您的回购已被推/克隆,请不要这样做,因为它会让事情变得糟糕!


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.

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

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.

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

Thanks!

解决方案

I finally managed to solve it.

The answer is:

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

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

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.

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

Note to visitors: do not do this if your repo has been pushed / cloned because it will mess things up badly!

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

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