27

git clone下代码window与unix换行问题

 4 years ago
source link: https://www.tuicool.com/articles/IfqUJjn
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

项目中避免不了会写一些shell脚本,使用ln软连接到一个目录。当git clone到windows中,ln连接显示无比怪异(如 ../xx) ,打开.sh文件后(仅仅是打开了),git status会看到该.sh文件做了修改,查看差异是LF【Unix and OS X(\n)】转成CRLF【Windows(\r\n)】,因为在winodws打开了使用了windows的换行符,若commit到仓库再git clone到linux操作系统是无法运行该shell脚本。

避免这一坑可从源头解决,windows下安装git.exe时点next下一步操作放慢点就会注意有个关于git和commit时使用何种风格,如下图:

NzayYvr.png!web

即使git安装时没有选择这一项,也可以在git clone 进行配置,如上图绿色框最后括号里面所说,具体配置命令如下:

git config --global core.autocrlf input

这样在PyCharm里面,随便打开刚刚git clone下项目中任何一个文件,在右下角都可见LF。在PyCharm中可通过以下两种方式进行设置file的换行符,如下图:

3eEZNnm.png!web

uABJnm7.png!web


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK