2022年11月26日 星期六

[Git 常見問題] error: The following untracked working tree files would be overwritten by merge

 Source From Here


方案1:
// x -----删除忽略文件已经对 git 来说不识别的文件
// d -----删除未被添加到 git 的路径中的文件
// f -----强制运行

# git clean -d -fx

方案2:
今天在服务器上 git pull 是出现以下错误:
  1. error: Your local changes to the following files would be overwritten by merge:  
  2.   
  3.         application/config/config.php  
  4.   
  5.         application/controllers/home.php  
  6.   
  7. Please, commit your changes or stash them before you can merge.  
  8.   
  9. Aborting  
不知道什么原因造成的代码冲突,处理方法如下. 如果希望保留生产服务器上所做的改动,仅仅并入新配置项:
$ git stash
$ git pull
$ git stash pop

然后可以使用 git diff -w +文件名 来确认代码自动合并的情况. 如果希望用代码库中的文件完全覆盖本地工作版本. 方法如下:
$ git reset --hard
$ git pull

方案3:

第 1 个问题: 解决 GIT 代码仓库不同步.
今天在执行 git pull 时出现:


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

第 2 个问题: git pull 的默认地址问题.
1. git 处于 master 这个 branch 下时,默认的 remote 就是 origin;
2. 当在 master 这个 brach 下使用指定 remote 和 merge 的 git pull 时,使用默认的 remote 和 merge。


但是对于自己建的项目,并用 push 到远程服务器上,并没有这块内容,需要自己配置。 如果直接运行 git pull,会得到如此结果:


解决方法, 通过 git config 进行如下配置:
$ git remote add -f origin git@192.168.21.44:rest.git
$ git config branch.master.remote origin
$ git config branch.master.merge refs/heads/master


1 則留言:

  1. Great article! Very helpful for readers looking for clear insights. For those interested in skill development, check out best training institute in Chennai offering quality courses. Helpful information about best guest posting sites.

    回覆刪除

[Git 常見問題] error: The following untracked working tree files would be overwritten by merge

  Source From  Here 方案1: // x -----删除忽略文件已经对 git 来说不识别的文件 // d -----删除未被添加到 git 的路径中的文件 // f -----强制运行 #   git clean -d -fx 方案2: 今天在服务器上  gi...