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

2023-05-16

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


本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

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

  • 只在一个文件上应用 git merge stategy 吗?

    当将一个分支合并到另一个分支时 可以定义合并策略 例如 git merge release X ours 当将发布分支中的内容合并到当前分支时 这会在全局范围内应用 我们的 策略 是否可以仅对一个特定文件应用此策略 例如 git merge
  • 将 git 与 svn 一起使用的好习惯

    Subversion 几年前就很流行 现在 git 也开始流行 越来越多的人想用 git 取代 Subversion 问题是很多项目都是基于 Subversion 的 所以问题是如何将 git 与 Subversion 一起使用 不要完全取
  • git 交互式变基:停止而不提交

    长话短说 有办法进去吗git rebase i停止编辑 没有提交 ID TLDR 更长的版本 背景 With git rebase i 我得到一个文本编辑器 我可以在其中定义命令列表 从pick COMMIT ID在每一行上 其中一个选项是
  • 即使在签出到另一个分支后也无法删除本地分支

    我正在尝试删除我的本地分支并尝试了我在这里找到的大多数解决方案 即签出到另一个分支然后运行git branch D or d
  • 没有共同的参考文献,也没有指定;什么也不做

    我有一个本地 git 项目 我想将其添加到 gitolite 中 显然这很难 所以我放弃了这个想法 我创建了一个新的 gitolite 存储库 将其添加到 gitolite admin conf gitolite conf 并提交并推送更改
  • 当必须同时使用 Git 和 Subversion 时如何处理 Git-svn

    Update 更详细地说 我尝试在家使用纯 Git 的原因是 我的公司希望迁移到 Git 但经理不愿意进行更改 因为开发人员不了解我们自己的存储库上的 Git 所以 我尝试做的是 我尝试让每个人都使用 Pure git 同时有人可以在这个学
  • 使用与后期步骤中的 Shell 脚本中的克隆相同的 http git 凭据

    我想要自动化我们的发布过程 并且我有一个 Maven 项目的以下 Jenkins 构建作业 使用配置的 Jenkins 凭证 用户名 密码 克隆 Git 存储库 执行一些 Maven 命令以进行构建 配置一个后步骤来执行一些额外的 Git
  • 获取引用而不下载对象[重复]

    这个问题在这里已经有答案了 我想检查 origin master 是否与我的 HEAD 不同 I do not想要git fetch 因为它可能非常昂贵 我滥用 git 的方式使得成本高得令人望而却步 任何允许我从远程获取提交列表或顶部提交
  • 在 git 中编辑分支?

    我在 github 网站上创建了一个分支 该分支不在我的本地存储库中 如何将该分支带到我的本地计算机 对其进行编辑 然后将其推送回我的 github 帐户 在本地工作目录中输入 git fetch origin newbranch git
  • 让“git pull”在拉取不同分支时要求确认

    当同时处理许多项目和分支时 我偶尔会犯一些愚蠢的错误 比如拉入错误的分支 例如在分支上master I did git pull origin dangerous code并且有一段时间没有注意到这一点 这个小错误造成了很大的混乱 当我尝试
  • git-http-backend 与 AuthzUnixGroup 无法正常工作

    我正在尝试在 CentOS 6 机器上的 Apache 2 2 上设置一个 git 存储库 并安装了 git 我尝试过许多不同的方向 但我却不知所措 我目前的情况包括能够clone正常 但完全无法推动 似乎我无法使身份验证位正常工作 因为我
  • git am:补丁格式检测失败

    我以前从未在 Git 中使用过补丁 我需要一些帮助 我正在尝试将补丁应用到 Git 存储库来测试 Wine 补丁 特别是这个补丁在这里 https bugs winehq org attachment cgi id 60752 所以我做了以
  • 如何将推送的分支复制到另一个目录?

    我有一个分支叫master 生产 另一个称为development 当我从 master 推送提交时 post receive 挂钩执行 git work tree var www mywebsite com git dir var rep
  • React Native:即使文件不存在,也会出现 hprof 文件太大错误

    当我尝试跑步时git push origin master在我的 React Native 应用程序中 我得到 file android java pid60072 hprof is 564 94 MB this exceeds GitHu
  • 通过 SFTP 克隆 Git 存储库

    每次我尝试克隆 Git 存储库时都会遇到致命错误 我运行这个 git clone sftp email protected cdn cgi l email protection git foobar git 我得到这个 fatal Unab
  • 如何对 git 子模块使用相同的协议?

    在 git 存储库 R 中 我有一个使用以下命令初始化的子模块 git submodule add git mygitserver 现在用户刚刚使用克隆 Rhttps并在运行时出现错误 git submodule init git subm
  • Ansible git clone“权限被拒绝”但直接 git clone 工作

    我在使用 Ansible 时遇到了一个令人不安的问题 我使用当前主机的 ssh 密钥在我的环境中设置 git 克隆 name Add user Public Key copy src Users alexgrs ssh id rsa pub
  • 为什么某些 Git 分支名称中包含斜杠?

    我正在阅读本教程https www atlassian com git tutorials syncing git fetch https www atlassian com git tutorials syncing git fetch
  • 从 Jenkinsfile 中获取有关其他分支的信息

    Jenkins Blue Ocean 与链接的 Bitbucket Server 实例在同一本地网络上运行 Jenkins 中的多分支项目能够为本地 Bitbucket 服务器上链接的 Bitbucket 存储库的每个分支创建一个分支 但在
  • git stash 和编辑帅哥

    我完全喜欢git add p and git stash但我偶尔会遇到以下问题 该问题是通过以下命令序列重现的 git add p my file 然后我手动编辑大块 using e 因为 git 建议的分割不适合我 git stash k

随机推荐