当要push代码到git时,出现提示:

error:failed to push some refs to ...

Dealing with “non-fast-forward” errors
From time to time you may encounter this error while pushing:

  1. $ git push origin master
  2. To ../remote/
  3. ! [rejected]        master -> master (non-fast forward)
  4. error: failed to push some refs to '../remote/'

To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes before pushing again.  See the 'non-fast forward'
section of 'git push --help' for details.
This error can be a bit overwhelming at first, do not fear. Simply put, git cannot make the change on the remote without losing commits, so it refuses the push. Usually this is caused by another user pushing to the same branch. You can remedy this by fetching and merging the remote branch, or using pull to perform both at once.
In other cases this error is a result of destructive changes made locally by using commands like git commit --amend or git rebase. While you can override the remote by adding --force to the push command, you should only do so if you are absolutely certain this is what you want to do. Force-pushes can cause issues for other users that have fetched the remote branch, and is considered bad practice. When in doubt, don’t force-push.

问题(Non-fast-forward)的出现原因在于:git仓库中已经有一部分代码,所以它不允许你直接把你的代码覆盖上去。于是你有2个选择方式:

1,强推,即利用强覆盖方式用你本地的代码替代git仓库内的内容

git push -f

2,先把git的东西fetch到你本地然后merge后再push

$ git fetch

$ git merge

这2句命令等价于

  1. $ git pull

可是,这时候又出现了如下的问题:

上面出现的 [branch "master"]是需要明确(.git/config)如下的内容
[branch "master"]
    remote = origin

merge = refs/heads/master

这等于告诉git2件事:

1,当你处于master branch, 默认的remote就是origin。

2,当你在master branch上使用git pull时,没有指定remote和branch,那么git就会采用默认的remote(也就是origin)来merge在master branch上所有的改变

如果不想或者不会编辑config文件的话,可以在bush上输入如下命令行:

  1. $ git config branch.master.remote origin
  2. $ git config branch.master.merge refs/heads/master

之后再重新git pull下。最后git push你的代码吧。it works now~

Git push错误non-fast-forward后的冲突解决的更多相关文章

  1. Git错误non-fast-forward后的冲突解决

    Git错误non-fast-forward后的冲突解决当要push代码到git时,出现提示: error:failed to push some refs to ... Dealing with “n ...

  2. Git分支(2/5) -- Fast Forward 合并

    快捷操作: 切换并创建分支: git checkout -b 分支名. git checkout -b some-change 然后我打开某个文件(index.html)修改一下标题. Commit之 ...

  3. git push 错误,回滚 push操作

    作者:故事我忘了¢个人微信公众号:程序猿的月光宝盒 0.记一次使用git push后,覆盖了同事代码的糗事 前言: ​ 都在WebStorm中操作,Idea或者PyCharm同理 ​ 为了高度还原尴尬 ...

  4. mzy git学习,禁用Fast forward的普通合并(六)

    git merge --no-ff -m "msg" x-branch:禁用Fast forward的普通合并 通常,合并分支时,如果可能,Git会用Fast forward模式, ...

  5. git push错误解决方案

    错误提示: error: The requested URL returned error: 403 Forbidden while accessing https://nanfei9330@gith ...

  6. github多用户git push错误remote: Permission to user1/z.git denied to user2

    背景:同一台电脑的public key同时添加到了github的两个账户,导致user1的仓库没法正常提交. 解决办法:为两个账户分别配置ssh key,配置~/.ssh/config文件(windo ...

  7. git push错误,如何回滚

    --> git push Counting objects: 81, done.Delta compression using up to 4 threads.Compressing objec ...

  8. git分支与版本管理、版本回退、冲突解决记录

    一.基础使用 1.初始化本地仓库 git init 2.关联远程仓库 git remote add origin git@github.com:用户名/仓库名.git 3.添加远程仓库文件到本地 gi ...

  9. Idea中Git的使用和两种类型的冲突解决

    一.Git冲突解决 在idea开发工具中使用Git时,主要用到的快捷按钮如下五个:   这五个按钮的使用说明及在idea中如何配置和使用git可参考https://github.com/DayThin ...

随机推荐

  1. 月下载量上千次的APP源码分享

    在360上面上线了一个月,下载量上千余次.这里把代码都分享出来,供大家学习哈!还包括教大家如何接入广告,赚点小钱花花,喜欢的帮忙顶一个,大神见了勿喷,小学僧刚学Android没多久. 首先介绍这款应用 ...

  2. ACM——Quicksum

    Quicksum 时间限制(普通/Java):1000MS/3000MS          运行内存限制:65536KByte总提交:615            测试通过:256 描述 A chec ...

  3. 国外一些知名ASP.Net开源CMS系统

    1.Ludico Ludico是C#编写的居于ASP.NET 2.0的Portal/CMS系统.它的模块化设计是你可以按照你希望的使用或开发网站功能.它里面有高级的用户管理,一个所见即所的(WYSIW ...

  4. JAVA调用WebService总结

    一.wximport自动生成代码 wsimport -keep -p com.test.client http://localhost:8080/test/services/TestService?w ...

  5. python输出1到100之和的几种方法

    1. 使用内建函数range print sum(range(1,101)) 2. 使用函数reduce print reduce(lambda a,b:a+b,range(1,101)) 3. 使用 ...

  6. Java实战之02Hibernate-07与效率性能相关配置

    十四.其他HIbernate配置(与效率,性能相关) 1.数据库连接池 Hibernate有默认的连接池,性能有问题,不适合实际应用,适合学习阶段.DriverManagerConnectionPro ...

  7. Update msi using vbscript

    参考: http://stackoverflow.com/questions/1609250/how-do-i-add-update-a-property-inside-an-msi-from-the ...

  8. sql的集合操作

    原文转自:http://blog.csdn.net/qsyzb/article/details/12560917 SELECT语句的查询结果是元组的集合,所以多个SELECT语句的结果可进行集合操作. ...

  9. Volley网络请求框架的基本用法

    备注: 本笔记是参照了 http://blog.csdn.net/ysh06201418/article/details/46443235  学习之后写下的 简介:  Volley是google官网退 ...

  10. tail报错

    在block和index都没有满的情况下,有如下报错: tail -f messages tail:cannot watch 'messages' : No space left on device ...