error:Your local changes to the following files would be overwritten by merge:
用git pull来更新代码的时候,遇到了以下报错信息:
error:Your local changes to the following files would be overwritten by merge: pay.php Please, commit your changes or stash them before you can merge. Aborting
原因:出现这个问题的原因是,在线上直接操作文件,而你本地恰好也修改了这个文件。这个时候执行 git pull时就产生冲突了。
解决方案:通过git stash 将工作区恢复到上次提交到内容,同时备份到本地所做到修改,之后就可以正常git pull了,git pull完成后,执行git bash pop将之前本地做的修改应用到当前工作区。
git stash
git pull
git stash pop
命令解释:
git stash 备份当前的工作内容区的内容,从最近的一次提交中读取相关内容,让工作区保证和上次提交的内容一致。同时,将当前的工作区内容保存到git栈中。
git pull 拉取服务器上的代码;
git stash pop从git栈中读取最近一次保存的内容,恢复工作区的相关内容。由于可能存在多个stash的内容,所以用栈来管理,pop会从最近的一个stash中读取内容并恢复。
git stash list显示git栈内的所有备份,可以利用这个列表来决定从哪个地方恢复。
git stash clear 清空git栈。此时若使用git相关的图形化工具会发现,原来的那些结点就消失了。