新手问题 [已解决] git push 还要另外设置?

chairy11 · 2014年04月27日 · 最后由 alsotang 回复于 2014年04月28日 · 6082 次阅读

问题:

最近 git push 老出现提示:

warning: push.default is unset; its implicit value is changing in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the current behavior after the default changes, use:

  git config --global push.default matching

To squelch this message and adopt the new behavior now, use:

  git config --global push.default simple

When push.default is set to 'matching', git will push local branches
to the remote branches that already exist with the same name.

In Git 2.0, Git will default to the more conservative 'simple'
behavior, which only pushes the current branch to the corresponding
remote branch that 'git pull' uses to update the current branch.

See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)

之前一直不就用这句的嘛?不是好好的嘛?为什么还要设置?

我糊里糊涂设置了

git config --global push.default matching

结果再 git push, 又显示

Counting objects: 34, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (10/10), done.
Writing objects: 100% (10/10), 1.37 KiB | 0 bytes/s, done.
Total 10 (delta 8), reused 0 (delta 0)
To [email protected]:realxxx/realxxx.git
   e178173..193exxx  feature/YBY -> feature/YBY
 ! [rejected]        develop -> develop (non-fast-forward)
error: failed to push some refs to '[email protected]:realxxx/realxxx.git'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and integrate the remote changes
hint: (e.g. 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

这是成功还是不成功?

 ! [rejected]        develop -> develop (non-fast-forward)
error: failed to push some refs 

这句说的是什么?我明明就是从 feature/YBY -> feature/YBY啊!

解决方案

git config --global push.default simple

开发机上也是由于升级环境,也同样出样这样的提示。表示还没有去理睬。

#3 楼 @hz_qiuyuanxin 其实还是不十分懂,我的本地分支与远程分支是同一个名字,而我目前一直在 feature/YBY、这个分支下操作。而我设置了 matching。而 develop 一直未把我的分支合并(时候未到)。

匿名 #5 2014年04月28日

git 升级了,push.default 的默认值改掉了,然后如果想用旧的行为就要自己改下。

后面 push 失败的错误应该和这个无关吧,只是远程在你 pull 之后又有更新,你需要先 pull 一下,本地 merge 完毕之后再 push。

#5 楼 @dorentus 最近都是我一个人在写,好像没看到任何要 pull 的更新啊,好诡异哦……

#4 楼 @chairy11

你应该设置为 simple

然后你的 develop 要合并 feature/YBY 应该是:

git checkout develop
git merge feature/YBY --no-ff
git push origin develop

楼主好好去看看 git 的文档吧!!

#7 楼 @hz_qiuyuanxin 各种看完就忘,再也不想看这类玩意了…… 之前《Git pro》,codeschool 的 Git 课程都看了两遍……

develop 分支到时不是我负责合并……

#8 楼 @chairy11 如果都要人教你手把手怎么做,那么这世界要你何用

  1. 第一个提示的话,改成

git config --global push.default simple

就好了。这是 git 2.0 的默认行为

  1. 第二个提示,是远程分支跟本地分支冲突导致的,这时候你 merge 一下远程分支,让服务器可以 fast forward 你的修改就解决了。这跟 1 无关。

#9 楼 @hz_qiuyuanxin 呵呵,也不是事事,只是有时发现这里发帖简直是解决问题的捷径!瞬间解决!所以,有点依赖性了……

前两年就是迷信自己琢磨自己看书,结果总是一卡住就半天,挺折磨的。哈哈,后来就学会了求助本论坛各位了……所有问题都非常快地解决,会感觉很顺畅很开心啊…… 就是求助太多有点不好意思…… RubyChina 好人多……

#10 楼 @alsotang 恩,谢谢,第一个昨天已经弄了。第二个先忽略吧,因为我远程分支没有其它人做过任何修改,一直是我自己在写,不可能需要 merge 什么的。等我琢磨明白了再行动,哈哈。

#11 楼 @chairy11

你现在应该问自己两个问题。git 的数据格式是怎么样的?push 对数据进行了何种操作?

#13 楼 @bhuztez 这么深奥……git 的数据格式?不懂……push?就是把我最新的变动 update 到我的远程分支呗……

匿名 #15 2014年04月28日

#13 楼 @bhuztez 只是把 git 当工具,日常用的话,为啥要去了解「git 的数据格式是怎么样」……

#12 楼 @chairy11 git fetch 之后看看分支情况就好。

需要 登录 后方可回复, 如果你还没有账号请 注册新账号