Git错误non-fast-forward
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:
- $ git push origin master
- To ../remote/
- ! [rejected] master -> master (non-fast forward)
- 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句命令等价于
- $ 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上输入如下命令行:
- $ git config branch.master.remote origin
- $ git config branch.master.merge refs/heads/master
之后再重新git pull下。最后git push你的代码吧。it works now~
Git错误non-fast-forward的更多相关文章
- Git:非Fast forward下的合并(--no-ff方式的git merge)
创建dev分支,并且修改readme.txt的内容,然后提交 使用git merge --no-ff -m "说明内容" 分支名称合并分支 使用git log --graph -- ...
- Git 分支管理 不使用Fast forward模式进行合并 分支管理策略
通常,合并分支时,如果可能,Git会用Fast forward模式,但这种模式下,删除分支后,会丢掉分支信息. 如果要强制禁用Fast forward模式,Git就会在merge时生成一个新的comm ...
- 【Todo】git的fast forward & git命令学习 & no-ff
git的fast-forward在之前的文章有介绍过,但是介绍的不细: http://www.cnblogs.com/charlesblc/p/5953066.html fast-forward方式就 ...
- mzy git学习,禁用Fast forward的普通合并(六)
git merge --no-ff -m "msg" x-branch:禁用Fast forward的普通合并 通常,合并分支时,如果可能,Git会用Fast forward模式, ...
- Git – Fast Forward 和 no fast foward
Git 很是强大,在体验过rebase的华丽之后,再次发现之前在TFS上遇到的问题一下都有解了.但也印证了Git深入并非易事.这篇就谈下一个容易迷糊的概念:Fast forward. Fast-For ...
- Git分支(2/5) -- Fast Forward 合并
快捷操作: 切换并创建分支: git checkout -b 分支名. git checkout -b some-change 然后我打开某个文件(index.html)修改一下标题. Commit之 ...
- Git的fast forward和no fast forward和 three way merge 以及squash(聚合)
github上上传了版本库https://github.com/ChuckGitMerge 包括merge和rebase 没时间画图,貌似也不太会用画图工具,先写了一个文字版本的 更新:2015年 ...
- git教程5-查看关系图与no fast forward融合
1.每一个提交相当于一个版本,版本都有版本号与之对应.通常通过git commit -m "name"为每次提交命名. 2.融合:即将次分支的最后一个版本添加到主分支上.当融合冲突 ...
- Git 关于Fast Forward提交的简单说明
多人协同开发,使用Git经常会看到警告信息包含术语:fast forward, 这是何义? 简单来说就是提交到远程中心仓库的代码必须是按照时间顺序的. 比如A从中心仓库拿到代码后,对文件f进行了修改. ...
- Git Fast Forward 和 no fast foward
如果执行了 Fast Forward,开发者根本不会看到这个分支,就像在 master 直接 commit 一样.
随机推荐
- Note_Master-Detail Application(iOS template)_05_ YJYMasterViewController.m
// YJYMasterViewController.m #import "YJYMasterViewController.h" #import "YJYDetailV ...
- 多动手试试,其实List类型的变量在页面上取到的值可以直接赋值给一个js的Array数组变量
多动手试试,其实List类型的变量在页面上取到的值可以直接赋值给一个js的Array数组变量,并且数组变量可以直接取到每一个元素var array1 = '<%=yearList =>'; ...
- 不能使用weak修饰进行声明的类
These classes include NSTextView, NSFont and NSColorSpace; for the full list, see Transitioning to A ...
- Linux----七个有效的文本编辑习惯
如果你要花大量的时间键入文本, 写程序或编写HTML脚本, 你可以通过有效地使用一个好的编辑器来替你节省时间. 本文将引导你如果快速地完成你的编辑工作, 并且减少你的错误. 本文将以开放源码软件Vim ...
- Ubuntu安装Fcitx(小企鹅五笔输入法)
安装配置如下: 1. 安装 fcitx sudo apt-get install fcitx 2. 配置默认输入法为 fcitx im-switch -s fcitx // 注意无须加 sudo 3. ...
- Postfix之mail.cf
1.# 2. 3.vi /etc/postfix/main.cf #vi编辑postfix配置文件 4.#找到如下配置项酌情修改 5.###### 6.myhostname = mail.yourd ...
- 并列div自动等高
并列div自动等高 方法一:css控制 <!DOCTYPE html> <html lang="en"> <head> <meta cha ...
- 完美解决方案,可排除DATASET不支持System.Nullable错误
完美解决方案,可排除DATASET不支持System.Nullable错误 using System; using System.Collections.Generic; using System.L ...
- Unity3d各平台资源路径文件夹
之前一直是PC项目,公司终于考虑移动平台了,但是试验了几把,感觉移动平台资源管理路径还是有很多隐藏的注意事项. 比如在PC上可以做到随便读写,但是在移动平台就涉及到权限问题. 看到小伙伴的总结,还是要 ...
- HDU 1082
http://acm.hdu.edu.cn/showproblem.php?pid=1082 这题开始想复杂了,error并不包括表达式本身不合法的情况 我的方法是遇到右括号就开始处理栈,如果开始最外 ...