git错误处理: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:

haoMBP:bn-android hao$ git pull
remote: Counting objects: 489, done.
remote: Compressing objects: 100% (306/306), done.
remote: Total 489 (delta 278), reused 219 (delta 113)
Receiving objects: 100% (489/489), 1.10 MiB | 310.00 KiB/s, done.
Resolving deltas: 100% (278/278), completed with 44 local objects.
From http://119.25.154.83:9080/haochuang/bn-android
   8a5f0f4..63dffd8  master     -> origin/master
Updating 8a5f0f4..63dffd8
error: Your local changes to the following files would be overwritten by merge:
    app/src/main/java/cn/haochuang/bn/ui/login/LoginActivity.java
Please commit your changes or stash them before you merge.
Aborting

 

处理办法:

意思是我台式机上新修改的代码的文件,将会被git服务器上的代码覆盖;我当然不想刚刚写的代码被覆盖掉,看了git的手册,发现可以这样解决:
方法1:如果你想保留刚才本地修改的代码,并把git服务器上的代码pull到本地(本地刚才修改的代码将会被暂时封存起来)

git stash
git pull origin master
git stash pop

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

 

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

git reset --hard
git pull origin master

 

posted @ 2018-08-10 10:07  念槐聚  阅读(1037)  评论(0)    收藏  举报