常见git冲突

git冲突 Your local changes to the following files would be overwritten by merge...
在使用git pull命令更新代码时遇到的如下错误:

// Your local changes to the following files would be overwritten by merge:
// config/index.js
// src/lgb/AUM/AUMIndex/AUMIndex.html/components/AUMIndex/AUMIndex.vue
// Please commit your changes or stash them before you merge.

出现上述错误的原因时 因为其他人修改了上述文件并提交到了版本库,而我们本地也修改了上述文件,这时进行pull时自然就会产生冲突。

解决方案

执行git stash命令将工作区恢复到上次提交的内容,同时将本地所做的修改备份到暂存区。这样整个项目就回到了我们修改之前的状态。
这是就可以正常git pull了
git pull完成后 执行git stash pop命令将之前本地做的修改应用到当前工作区。

相关命令

git stash //备份当前的工作区的内容,从最近的一次提交中读取相关内容,让工作区保证和上一次提交的内容一致,同时将当前的工作区内容保存在暂存区中
git pull //拉取服务器上的代码到本地
git stash pop //从暂存区读取最近一次保存的内容,恢复工作区的相关内容
//由于可能存在多个stash内容,所以用栈来管理,pop会从最近的一个stash中读取内容并回复
git stash list //显示暂存区中的所有备份,可以利用这个列表来决定从哪个地方回复
git stash clear //清空暂存区
posted @ 2021-01-06 15:18  背锅侠-渣渣关😩  阅读(89)  评论(0)    收藏  举报