How to undo the damage of autocrlf?

半世苍凉 提交于 2019-12-23 12:27:52

问题


I've been using git with autocrlf set to true for a while. I've been using it with git-svn through cygwin. It's been causing me a bunch of problems and I see here and here that I should probably turn it off. How can I "undo the damage" between trunk and master?


回答1:


If you just want to fix it in a single commit and then leave it alone, you could do something like:

find . -not \( -path ./.git -prune \) -type f -exec sed -i -e 's/\r//g' {} +

Note: This will remove CRs from every file in the repository. Add -name '*.someext' or other clauses after -type f to adjust the find's extent.

If you want to edit prior commits (note that this will break other people trying to merge their changes into your branch!), you can use git filter-branch - write a script that does something similar to the find invocation above, then pass it in with something like

git filter-branch --tree-filter /full/path/to/myscript.sh master otherbranch

This will rewrite history, eliminating any CR that has ever been in the source code repository. Note that this will likely break git-svn if you run it across any commits created by git-svn. You can use something like trunk..mylocalbranch to only run it on local commits.



来源:https://stackoverflow.com/questions/6117678/how-to-undo-the-damage-of-autocrlf

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!