git 解决pull origin 错误 error: The following untracked working tree files would be overwritten by merge

error: The following untracked working tree files would be overwritten by merge:


        bin/AndroidManifest.xml
Please move or remove them before you can merge.
Aborting


方案1:
git clean  -d  -fx ""
其中 
x  -----删除忽略文件已经对git来说不识别的文件
d  -----删除未被添加到git的路径中的文件

f  -----强制运行

方案2:

今天在服务器上git pull是出现以下错误:

error: Your local changes to the following files would be overwritten by merge:

        application/config/config.php

        application/controllers/home.php

Please, commit your changes or stash them before you can merge.

Aborting

不知道什么原因造成的代码冲突,处理方法如下:

如果希望保留生产服务器上所做的改动,仅仅并入新配置项:

git stash

git pull

git stash pop

然后可以使用git diff -w +文件名 来确认代码自动合并的情况.

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

git reset --hard

git pull


方案3:

第1个问题: 解决GIT代码仓库不同步

今天在执行git pull时出现:

 
 
  1. [root@gitserver /data/work/www/rest/lib/Business/Inventory]# git pull  
  2. Enter passphrase for key '/root/.ssh/id_rsa':  
  3. Updating 70e8b93..a0f1a6c  
  4. error: Your local changes to the following files would be overwritten by merge:  
  5.         rest/lib/Business/Inventory/ProductStatus.php  
  6. Please, commit your changes or stash them before you can merge.  
  7. Aborting 

解决方法:
执行git checkout -f,然后再执行git pull重新checkout

 
 
  1. [root@gitserver /data/work/www/rest/lib/Business/Inventory]# git checkout -f  
  2. Your branch is behind 'origin/master' by 2 commits, and can be fast-forwarded. 

再执行git pull时就可以了:

 
 
  1. [root@gitserver /data/work/www/rest/lib/Business/Inventory]# git pull  
  2. Enter passphrase for key '/root/.ssh/id_rsa':  
  3. Updating 70e8b93..a0f1a6c  
  4. Fast-forward 
  5.  rest/lib/Business/Inventory/ProductStatus.php |    1 +  
  6.  1 files changed, 1 insertions(+), 0 deletions(-)  
  7.  mode change 100644 => 100755 rest/lib/Business/Inventory/ProductStatus.php 

 

第2个问题: git pull的默认地址问题.

1.git处于master这个branch下时,默认的remote就是origin;
2.当在master这个brach下使用指定remote和merge的git pull时,使用默认的remote和merge。
 
但是对于自己建的项目,并用push到远程服务器上,并没有这块内容,需要自己配置。
如果直接运行git pull,会得到如此结果:

#当执行git pull之后的提示:

 
 
  1. $ git pull  
  2. Password:  
  3. You asked me to pull without telling me which branch you  
  4. want to merge withand 'branch.master.merge' in 
  5. your configuration file does not tell me, either. Please  
  6. specify which branch you want to use on the command line and 
  7. try again (e.g. 'git pull <repository> <refspec>').  
  8. See git-pull(1) for details.  
  9.    
  10. If you often merge with the same branch, you may want to 
  11. use something like the following in your configuration file:  
  12.    
  13. [branch "master"]  
  14.  remote = <nickname>  
  15.  merge = <remote-ref>  
  16.    
  17. [remote "<nickname>"]  
  18.  url = <url>  
  19.  fetch = <refspec>  
  20.    
  21. See git-config(1) for details. 

#解决方法, 通过git config进行如下配置.

 
 
  1. git remote add -f origin git@192.168.21.44:rest.git  
  2. git config branch.master.remote origin  
  3. git config branch.master.merge refs/heads/master 

方案3出自 “ritto's blog” 博客,请务必保留此出处http://ritto.blog.51cto.com/427838/741342


  • 7
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值