git pull遇到错误:error: Your local changes to the following files would be overwritten by merge:

Posted Alighieri

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了git pull遇到错误:error: 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:,则可用以下方法解决:

  方法1:如果你想保留刚才本地修改的代码,并把git服务器上的代码pull到本地(本地刚才修改的代码将会被暂时封存起来)

git stash
git pull origin master
git stash pop

如此一来,服务器上的代码更新到了本地,而且你本地修改的代码也没有被覆盖,之后使用add,commit,push 命令即可更新本地代码到服务器了。

方法2、如果你想完全地覆盖本地的代码,只保留服务器端代码,则直接回退到上一个版本,再进行pull:

git reset --hard
git pull origin master 

注:其中origin master表示git的主分支。

以上是关于git pull遇到错误: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:

git pull 报错 error: cannot pull with rebase: Your index contains uncommitted changes.

git pull 报错 error: cannot pull with rebase: Your index contains uncommitted changes.

git pull --rebase 报错 error: cannot pull with rebase: Your index contains uncommitted changes.

git pull --rebase 报错 error: cannot pull with rebase: Your index contains uncommitted changes.

git 常见冲突—— git pull遇到报错Your local changes to the following files would be overwritten by merge