美文网首页
git合并代码之.gitignore

git合并代码之.gitignore

作者: 可齐 | 来源:发表于2016-04-18 18:11 被阅读780次

    在git合并代码的过程中,反复遇到一个问题:不同机器上传的代码,在git pull时候报错如下

    error: Your local changes to the following files would be overwritten by merge:
    .DS_Store
    

    Please, commit your changes or stash them before you can merge.

    原因

    • 合并时,将系统目录隐藏文件进行了比对,不同机器的当然一直存在冲突

    解决办法

    • 在显示Finder隐藏文件模式下,进入/User目录下,查看.gitignore_global

        # .gitignore_global
        ####################################
        ######## OS generated files ########
        ####################################
        .DS_Store
        .DS_Store?
        *.swp
        ._*
        .Spotlight-V100
        .Trashes
        Icon?
        ehthumbs.db
        Thumbs.db
        ####################################
        ############# packages #############
        ####################################
        *.7z
        *.dmg
        *.gz
        *.iso
        *.jar
        *.rar
        *.tar
        *.zip
      
    • 务必保证.DS_Store在忽略名单内!!!!!!

    • 然后,进到你的项目目录,查看.git文件夹下,config配置,添加这一行,当然,目录请指向你的.gitignore_global

    • 这部分的意思是,保证你的项目,引用了全局的gitignore,即忽略了那些应该忽略的东西

        excludesfile = /Users/apple/.gitignore_global 
      

    成功在即

    好了,现在删除下你本地的.DS_Store,然后再pull一次吧,大功告成~

    2016-4-21更新

    哎,又出新的坑了,手动删除.DS_Store,还是不管用!。。。google结果如下,执行后,再pull就没事了

    http://stackoverflow.com/questions/14744993/git-strange-branch-merge-error-that-i-am-not-sure-how-to-solve

    rm .DS_Store
    git add -A
    git commit -m "Added .gitignore file"
    

    感谢stackoverflow 感谢warrenm

    如果你的.DS_Store未忽略就已经push上传,那么它已经被git跟踪,需要执行终端清理git缓存,

        git rm -r --cached [文件名]
    

        git rm -r --cached .DS_Store
    

    重置所有跟踪

        git rm -r --cached .
        git add .
        git commit -m 'update .gitignore'
    

    生成ignore文件工具

    发现一个工具,可以生成各种语言环境下ignore文件
    https://www.gitignore.io/

    相关文章

      网友评论

          本文标题:git合并代码之.gitignore

          本文链接:https://www.haomeiwen.com/subject/lnsalttx.html