您的位置:首页 > 编程语言

Git代码冲突常见解决方法

2016-05-27 00:00 218 查看
[code=plain]error: Your local changes to the following files would be overwritten by merge:
protected/config/main.php
Please, commit your changes or stash them before you can merge.

发生这类错误怎么办呢,其实人家已经告诉你了,commit your changes or stash them,但是

commit操作是做不了了,只能stash.

步骤:

[code=plain]git stash //先把自己已经修改了的代码隐藏起来,可用git stash list查看隐藏起来的代码
git pull  //拉下来远程仓库里的代码
git stash pop //把自己隐藏起来的代码释放出来,git会自动合并,然后有冲突的文件就会报错,最后具体手动修改

希望用代码库中的文件完全覆盖本地工作版本. 方法如下:

[code=plain]git reset --hard
git pull

其中git reset是针对版本,如果想针对文件回退本地修改,使用:

[code=plain]git checkout HEAD file/to/restore
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  git stash