Git问题non-fast-forward解决
2016-03-27 19:36
302 查看
当要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:
[plain] view
plain copy
print?
$ 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.
![](http://my.csdn.net/uploads/201204/19/1334803176_7047.png)
问题(Non-fast-forward)的出现原因在于:git仓库中已经有一部分代码,所以它不允许你直接把你的代码覆盖上去。于是你有2个选择方式:
1,强推,即利用强覆盖方式用你本地的代码替代git仓库内的内容
git push -f
2,先把git的东西fetch到你本地然后merge后再push
$ git fetch
$ git merge
这2句命令等价于
[plain] view
plain copy
print?
$ git pull
可是,这时候又出现了如下的问题:
![](http://my.csdn.net/uploads/201204/19/1334803661_1873.png)
上面出现的 [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上输入如下命令行:
[plain] view
plain copy
print?
$ git config branch.master.remote origin
$ git config branch.master.merge refs/heads/master
error:failed to push some refs to ...
Dealing with “non-fast-forward” errors
From time to time you may encounter this error while pushing:
[plain] view
plain copy
print?
$ 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.
![](http://my.csdn.net/uploads/201204/19/1334803176_7047.png)
问题(Non-fast-forward)的出现原因在于:git仓库中已经有一部分代码,所以它不允许你直接把你的代码覆盖上去。于是你有2个选择方式:
1,强推,即利用强覆盖方式用你本地的代码替代git仓库内的内容
git push -f
2,先把git的东西fetch到你本地然后merge后再push
$ git fetch
$ git merge
这2句命令等价于
[plain] view
plain copy
print?
$ git pull
可是,这时候又出现了如下的问题:
![](http://my.csdn.net/uploads/201204/19/1334803661_1873.png)
上面出现的 [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上输入如下命令行:
[plain] view
plain copy
print?
$ git config branch.master.remote origin
$ git config branch.master.merge refs/heads/master
相关文章推荐
- 树莓派瞎玩~4~控制GPIO
- 单链表的实现(具有取并集的功能)
- Uva305——Joseph
- JavaI/O体系详解
- 数据结构_KMP
- http https session丢失
- eclipse导入maven项目时报Could not calculate build plan: Plugin org.apache.maven.plugins:maven-resources
- 继承与多态
- 转载:SqlServer数据库性能优化详解
- #pragma pack(n)
- iOS之使用距离传感器(靠近/远离屏幕-变暗/变亮)
- 1001. 害死人不偿命的(3n+1)猜想 (15)
- C++中有关多态和继承的那些事
- Struts2内建的拦截器
- lubuntu操作及桌面配置(2)
- 文章标题
- 自己做工程项目中的心得体会
- 169. Majority Element
- JavaScript作用域和变量提升
- MATLAB中利用多幅图片生成GIF动画