当前位置:   article > 正文

git push 失败的处理方式_! [rejected] dev -> dev (fetch first) error: faile

! [rejected] dev -> dev (fetch first) error: failed to push some refs to 'ht

远程创建了含有Readme的仓库, 本地初始化并添加了远程仓库后, push却失败了, 出现提示:

$ git push origin dev

  1. To https://git.oschina.net/erchoc/laradock.git
  2. ! [rejected] dev -> dev (fetch first)
  3. error: failed to push some refs to 'https://git.oschina.net/erchoc/laradock.git'
  4. hint: Updates were rejected because the remote contains work that you do
  5. hint: not have locally. This is usually caused by another repository pushing
  6. hint: to the same ref. You may want to first integrate the remote changes
  7. hint: (e.g., 'git pull ...') before pushing again.
  8. hint: See the 'Note about fast-forwards' in 'git push --help' for details.

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

  1. 1. 强推,即利用强覆盖方式用你本地的代码替代git仓库内的内容: git push -f
  2. 2. 先把git的东西fetch到你本地然后merge后再push
  3. - $ git fetch
  4. - $ git merge
  5. 2句命令等价于
  6. $ git pull

可是, 有时候还会出现问题:

  1. 上面出现的 [branch "master"]是需要明确(.git/config)如下的内容
  2. [branch "master"]
  3. remote = origin
  4. merge = refs/heads/master
  5. 这等于告诉git2件事:
  6. 1,当你处于master branch, 默认的remote就是origin。
  7. 2,当你在master branch上使用git pull时,没有指定remote和branch,那么git就会采用默认的remote(也就是origin)来merge在master branch上所有的改变
  8. 如果不想或者不会编辑config文件的话,可以在bush上输入如下命令行:
  9. $ git config branch.master.remote origin
  10. $ git config branch.master.merge refs/heads/master
  11. 之后再重新git pull下。最后git push你的代码吧。

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/533028
推荐阅读
相关标签
  

闽ICP备14008679号