当前位置:   article > 正文

Git基础(三)--常见错误及解决方案_no changes added to commit (use "git add" and/or "

no changes added to commit (use "git add" and/or "git commit -a")

常见错误

1.You have unmerged files

  1. $ git status
  2. On branch master
  3. You have unmerged paths.
  4. (fix conflicts and run "git commit")
  5. Unmerged paths:
  6. (use "git add <file>..." to mark resolution)
  7. both modified: index.html
  8. no changes added to commit (use "git add" and/or "git commit -a")</file>

解决方案:查看发生冲突的文件,手动修改后commit,通过 git mergetool 可以看到图形化的界面,便于直观的理解。

2.add操作warning

  1. $ git add -A
  2. warning: LF will be replaced by CRLF in file
  3. The file will have its original line endings in your working directory.</code>

原因:Linux平台下的换行符是 LF,而Windows下则是 CRLF,所以当你再 Windows 保存文件时候,换行符会被保存为
建议:统一换行符为 LF

解决方案:Git 命令行输入如下命令,禁止自动转换换行符

git config --global core.autocrlf false

3.git pull 失败

  1. You have not concluded your merge (MERGE_HEAD exists).
  2. Please, commit your changes before you can merge.

原因:之前进行 Pull 操作时自动合并失败,和原文件有冲突
解决方案:取消 Pull 操作然后手动合并

取消合并:

git merge --abort

git reset --merge

解决冲突 重新 add and commit 拉取分支然后合并,git pull

4.push error

  1. $ git push origin master
  2. To john@githost:simplegit.git
  3. ! [rejected] master -> master (non-fast forward)
  4. error: failed to push some refs to 'john@githost:simplegit.git'

原因:之前有人进行过提交,本地项目并不是最新的,在提交之前,必须合并当前分支至最新
解决方案:git merge origin/master,当你直接在master分支的时候,可以git pull,相当于git fetch + git merge

5.checkout:unable to create '/path/project/.git/index.lock'

Git - fatal: Unable to create '/path/my_project/.git/index.lock': File exists.

解决方案:rm -f ./.git/index.lock

总结

有一条准则谨记,任何命令中带有 –hard 参数的都谨慎执行,很有可能造成不可逆的损失。

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/495557
推荐阅读
相关标签
  

闽ICP备14008679号