git 代码仓库拷贝问题

来源:互联网 发布:南风知我意叶小意txt 编辑:程序博客网 时间:2024/06/03 22:11

问题:

代码仓库从Windows拷贝到Linux,没有人为改动,却出现大量的文件改动

Changed but not updated

# git status# On branch master# Your branch is ahead of 'origin/master' by 2 commits.## Changed but not updated:#   (use "git add <file>..." to update what will be committed)#   (use "git checkout -- <file>..." to discard changes in working directory)##       modified:   CC++/Log_Kafka/Inc/ConfigRead.h#       modified:   CC++/Log_Kafka/Inc/DataStore.h#       modified:   CC++/Log_Kafka/Inc/Log.h

原因:

整个目录所有文件全部Modified,当查看文件内容时,却看不到任何改动。
最后,终于想到是换行符的问题。
Windows 和 Linux的回车换行符是有差别的:

os 标识符 code 字符 Windows CR LF 0x0D 0x0A \r\n Linux LF 0x0A \n

当将Windows 的代码库拷贝到Linux,回车换行符被替换,文件就会出现change;

解决办法:

  • 方法1:撤销改动

    代码仓库中执行
    $ git checkout

  • 方法2:压缩文件进行拷贝

    在Windows将代码库打包压缩,然后再拷贝到Linux。

另外:

Windows代码库NFS共享到Linux,在Linux下使用代码库时,有可能出现git 命令无法使用的情况。原因是代码库目录下.git目录的权限被改动,可执行权限消失,从而导致git命令失效。这个也要注意。

原创粉丝点击