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. 检测INT3 软断点

    “INT3”断点指令的机器码是 “0xcch” 检测思路,取函数地址,判断第一个字节是不是 “CCh” BYTE bFirst = ; ProcAddres = GetProcAddress(Load ...

  2. hdu 2049

    Ps:WA了无限次...简直做到崩溃..高中学的知识都忘了....这道题就是跟2048差不多.. 从N个人里选M个人,有Cmn种选法,然后就是M的错排*Cnm 代码: #include "s ...

  3. ubuntu  输入时弹出剪切板候选项

    fcitx很坑的把这个功能的快捷键设置成了ctrl + ;结果我在用vim的时候怎么也 没法输入command 不知道是哪次更新引入的,简直是坑人! 我找了半天系统设置都没找到这个快捷键是在哪设置的. ...

  4. BZOJ 2292 永远挑战

    最短路. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm&g ...

  5. Java Serializable

    实现Serializable的class表明object可以被保存. 被保存的时候实际是存储class里的instance variable,这样在deserialization的时候可以恢复obje ...

  6. 数位dp-POJ-3252-Round Numbers

    最近一直在看书和博客,即使做出几道题来也是看别人题解写的,感觉没自己的东西,所以很久没更新博客 看了很多数位dp的题和题解,发现数位dp题是有固定的模版的,并且终于自己做出来一道. 我觉得用记忆化搜索 ...

  7. grunt 执行

    几天以前,我决定开始启用一个CSS预处理器,找了很久,我选择了SASS并且尝试着去安装它.但是这似乎不是一件简单的事,在安装过程中出现了许多让我始料不及的问题,我很沮丧,但查找了很多资料,我终于找到了 ...

  8. iOS APP上线流程

    前言:作为一名IOS开发者,把开发出来的App上传到App Store是必须的.下面就来详细介绍下具体流程. 1.打开苹果开发者中心:https://developer.apple.com 打开后点击 ...

  9. vs常用调试快捷键

    vs2005常用调试快捷键 ,开发起来更加的方面,虽然现在vs2008发布了,但vs2005还是一个主流,个人还是用vs2005,调试代码也多. F6: 生成解决方案Ctrl+F6: 生成当前项目F7 ...

  10. C# 如何执行bat文件 传参数

    C# 如何执行bat文件 传参数 分类: C# basic 2011-04-25 18:55 3972人阅读 评论(0) 收藏 举报 c#stringpathoutput Process p = ne ...