Git基础(三)--常见错误及解决方案

常见错误

1.You have unmerged files

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

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

2.add操作warning

$ git add -A
warning: LF will be replaced by CRLF in file
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 失败

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

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

取消合并:

git merge --abort

git reset --merge

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

4.push error

$ git push origin master
To john@githost:simplegit.git
! [rejected] master -> master (non-fast forward)
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 参数的都谨慎执行,很有可能造成不可逆的损失。

 

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值