本文翻译自:How do I ignore an error on 'git pull' about my local changes would be overwritten by merge?

How do I ignore the following error message on Git pull? 如何忽略有关Git pull的以下错误消息?

Your local changes to the following files would be overwritten by merge 您对以下文件的本地更改将被合并覆盖

What if I want to overwrite them? 如果我想覆盖它们怎么办?

I've tried things like git pull -f , but nothing works. 我已经尝试过git pull -f类的东西,但是没有任何效果。

To be clear, I only want to overwrite specific changes, not everything. 需要明确的是,我只想覆盖特定的更改,而不是所有内容。


#1楼

参考:https://stackoom.com/question/y4pG/如何忽略有关本地更改的-git-pull-错误-因为合并会覆盖我的本地更改


#2楼

If you want remove all local changes from your working copy, simply stash them: 如果要从工作副本中删除所有本地更改,只需将它们存储起来:

git stash save --keep-index

If you don't need them anymore, you now can drop that stash: 如果您不再需要它们,现在可以删除该存储:

git stash drop

If you want to overwrite only specific parts of your local changes, there are two possibilities: 如果只想覆盖本地更改的特定部分,则有两种可能性:

  1. Commit everything you don't want to overwrite and use the method above for the rest. 提交所有您不想覆盖的内容,其余使用上面的方法。

  2. Use git checkout path/to/file/to/revert for the changes you wish to overwrite. 使用git checkout path/to/file/to/revert来覆盖您想要覆盖的更改。 Make sure that file is not staged via git reset HEAD path/to/file/to/revert . 确保未通过git reset HEAD path/to/file/to/revert


#3楼

If you want to overwrite specific changes, you need some way of telling it which ones you want to forget. 如果要覆盖特定的更改,则需要某种方式告诉它要忘记的更改。

You could try selectively stashing the changes you want to abandon using git stash --patch and then dropping that stash with git stash drop . 你可以尝试选择性地积攒你想用放弃修改git stash --patch然后滴加与藏匿git stash drop You can then pull in the remote changes and merge them as normal. 然后,您可以拉入远程更改并按常规合并它们。


#4楼

Alright with the help of the other two answers I've come up with a direct solution: 在其他两个答案的帮助下,我提出了一个直接的解决方案:

git checkout HEAD^ file/to/overwrite
git pull

#5楼

Here is a solution that throws away staged changes: 这是一个解决方案,可消除分阶段进行的更改:

git reset file/to/overwrite
git checkout file/to/overwrite

#6楼

如果您的存储库包含一些已从master删除的文件:

  1. git checkout master
  2. git fetch origin
  3. git reset --hard origin/master
  4. git checkout -b newbranch

如何忽略有关本地更改的“ git pull”错误,因为合并会覆盖我的本地更改?相关推荐

  1. 删除本地文件后 Git pull从远程仓库重新获取不到解决办法

    删除本地文件后,想从远程仓库中重新新Pull最新代码,但是执行了git pull命令后始终无法拉取下来 提示 Already up-to-date. 原因:当前本地库处于另一个分支中,需将本分支发He ...

  2. git使用git pull不能把全部分支拉取到本地

    git将远程分支拉取到本地 sunleejon 2019-09-04 20:05:33 69 收藏 版权 git pull origin master:localbranch 命令格式如上,git p ...

  3. git pull fatal: 拒绝合并无关的历史

    在git仓库中新建了一个仓库,想要把本地的项目传上去 在项目中: git init git add . git commit "提交说明" 连接远程主机: git remote a ...

  4. git pull 无法下载合并 报错:refusing to merge unrelated histories

    场景 我本地的代码和线上的代码,需要合并一下,因为线上的代码有修改的地方,我本地的代码也有修改的地方,直接覆盖会有问题,于是想到了用git(平时不用,直接ftp拉上去直接覆盖的),把修改过的文件,合并 ...

  5. Git pull 错误:fatal: refusing to merge unrelated histories解决办法

    描述 在使用git pull origin master拉取github代码时,报以下错误: fatal: refusing to merge unrelated histories 解决办法 将gi ...

  6. git pull 远程代码仓库未同步更新到本地?

    1.查看本地和远程仓库分支是否一致: git 查看本地和远程分支:(颜色区分,标红的是远程分支) git branch 2.排查是否处于git clone 的目录下 git remote --verb ...

  7. git reset后本地拉取_【转】【Mac + Git】之Git pull 强制拉取并覆盖本地代码

    关于实现手机端自动获取天气的demo 博主大二做的一个项目,当时很傻很天真,但是还是贴出来,希望能给大家一点帮助.欢迎转载哦!我的博客园地址:http://www.cnblogs.com/nature ...

  8. git pull常见用法

    git pull git pull的作用是从一个仓库或者本地的分支拉取并且整合代码.git pull的一般形式为 git pull <远程主机名> <远程分支名>:<本地 ...

  9. 彻底理解git 本地分支与远程分支,以及git pull与git fetch的区别, 以及git status输出的“Your branch is behind xxx”

    git 本地分支: 当clone一个远程repo之后,默认会新建一个master或main的本地分支. 比如: $ git branch -a * mainremotes/origin/HEAD -& ...

最新文章

  1. ios开发入门篇(四):UIWebView结合UISearchBar的简单用法
  2. [转]被当做狗和鸡来驱赶的百姓
  3. 消息中间件 rabbitMQ
  4. 在Ubuntu 18.04上搭建HttpRunnerManager服务
  5. 如何处理IE首页被篡改的问题
  6. 华为华三开启snmp服务
  7. 不用空格怎么打两个空格_为什么在寸土寸金的键盘上,空格键却要做这么长,究竟怎么回事?...
  8. epson r1900 清零软件_爱普生打印机清零软件
  9. 会计初级可以自己报名吗_2019初级会计职称考试报名流程全攻略
  10. 华为HarmonyOS手机系统如何下载手机淘宝APP领取淘宝内部隐藏优惠券?
  11. 三极管9013 9014 跟8050之间有什么区别,
  12. mysql innerdb 索引,MySQL系列-InnoDB索引优化AHI、Change buffer
  13. 坐标系统和glMatrix(GLM)
  14. WPS参考文献自动生成方法
  15. 素数模同余式次数与其解数的关系
  16. 【必会】SQL 命令大全
  17. this的三种常见用法
  18. 【Linux】3.0Linux进程概念
  19. linux nvcc未找到命令,NVCC CUDA编译流程
  20. 隆重推荐:大明王朝1566

热门文章

  1. only has output.xml, how to check failed step.
  2. 经典OA办公协同管理-原型UI设计-制作
  3. 关于缩短编写代码数据花费时间的问题
  4. cvs的console输出含义
  5. 由数据库对sql的执行说JDBC的Statement和PreparedStatement
  6. 初涉龙芯I/龙芯II
  7. 题解报告:hdu 1754 I Hate It(线段树)
  8. Python 基础总结
  9. Batch normalization:accelerating deep network training by reducing internal covariate shift的笔记
  10. ImageNet 数据集