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

[日期:2012-04-21] 来源:Linux社区  作者:chain2012 [字体: ]
 

当要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 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错误non-fast-forward的更多相关文章

  1. Git:非Fast forward下的合并(--no-ff方式的git merge)

    创建dev分支,并且修改readme.txt的内容,然后提交 使用git merge --no-ff -m "说明内容" 分支名称合并分支 使用git log --graph -- ...

  2. Git 分支管理 不使用Fast forward模式进行合并 分支管理策略

    通常,合并分支时,如果可能,Git会用Fast forward模式,但这种模式下,删除分支后,会丢掉分支信息. 如果要强制禁用Fast forward模式,Git就会在merge时生成一个新的comm ...

  3. 【Todo】git的fast forward & git命令学习 & no-ff

    git的fast-forward在之前的文章有介绍过,但是介绍的不细: http://www.cnblogs.com/charlesblc/p/5953066.html fast-forward方式就 ...

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

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

  5. Git – Fast Forward 和 no fast foward

    Git 很是强大,在体验过rebase的华丽之后,再次发现之前在TFS上遇到的问题一下都有解了.但也印证了Git深入并非易事.这篇就谈下一个容易迷糊的概念:Fast forward. Fast-For ...

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

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

  7. Git的fast forward和no fast forward和 three way merge 以及squash(聚合)

    github上上传了版本库https://github.com/ChuckGitMerge   包括merge和rebase 没时间画图,貌似也不太会用画图工具,先写了一个文字版本的 更新:2015年 ...

  8. git教程5-查看关系图与no fast forward融合

    1.每一个提交相当于一个版本,版本都有版本号与之对应.通常通过git commit -m "name"为每次提交命名. 2.融合:即将次分支的最后一个版本添加到主分支上.当融合冲突 ...

  9. Git 关于Fast Forward提交的简单说明

    多人协同开发,使用Git经常会看到警告信息包含术语:fast forward, 这是何义? 简单来说就是提交到远程中心仓库的代码必须是按照时间顺序的. 比如A从中心仓库拿到代码后,对文件f进行了修改. ...

  10. Git Fast Forward 和 no fast foward

    如果执行了 Fast Forward,开发者根本不会看到这个分支,就像在 master 直接 commit 一样.

随机推荐

  1. android 经典下雨效果

    英文原文地址:https://blog.stylingandroid.com/snowfall/ 中文翻译地址:http://www.open-open.com/lib/view/open145226 ...

  2. 《Objiect》

    [16-1]Object概述&Object-equals方法&toString方法. ================================================= ...

  3. acm 20140825

    为了自己的梦想,一次次的选择坚强.走上acm这条路,怎么也找不到让自己放弃的理由.我喜欢这种竞赛的氛围,我渴望在赛场上飞扬!想想过去的一个学习,自己并没有干点什么有意义的事.acm也没有好好的做!新的 ...

  4. POJ 2887 Big String (块状数组)

    题意:给一个字符串(<=1000000)和n个操作(<2000),每个操作可以在某个位置插入一个字符,或者查询该位置的字符.问查询结果. 思路:块状数组. 如果将原来的字符串都存在一起,每 ...

  5. JSON.parse()和JSON.stringify() 的用法区别

    parse用于从一个字符串中解析出json对象,如 var str = '{"name":"huangxiaojian","age":&qu ...

  6. numpy中的broadcast

    关于broadcast,官方文档描述如下: Each universal function takes array inputs and produces array outputs by perfo ...

  7. UIkit框架介绍

    UIKit Framework The UIKit framework (UIKit.framework) provides crucial infrastructure for implementi ...

  8. 【LEETCODE OJ】Reorder List

    Problem link: http://oj.leetcode.com/problems/reorder-list/ I think this problem should be a difficu ...

  9. Best Cow Fences_二分&&DP

    Description Farmer John's farm consists of a long row of N (1 <= N <= 100,000)fields. Each fie ...

  10. session 和 cookie 的区别和联系

    二者的定义: 当你在浏览网站的时候,WEB 服务器会先送一小小资料放在你的计算机上,Cookie 会帮你在网站上所打的文字或是一些选择,都纪录下来.当下次你再光临同一个网站,WEB 服务器会先看看有没 ...