0

几周前,我开始使用 git,我喜欢使用它。

但我想知道,为什么我在做 a 时总是被拒绝git push(推送有效,即使我得到那个错误)。

我有以下设置:

master
 \_ development
     \_ feature/blog*

现在我正在研究我从开发中创建的功能/博客。当我制作时,git push我收到以下错误消息:

$ git push
[...]
To [...]@[...]:[...]
   288274e..34c17c3  feature/blogs -> feature/blogs
 ! [rejected]        development -> development (non-fast-forward)
error: failed to push some refs to '[...]@[...]:[...]'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again.  See the
'Note about fast-forwards' section of 'git push --help' for details.

即使我这样做git pull也行不通。我也收到一条Already up-to-date.消息。

如何防止该错误?我只想推送当前签出的分支。

4

2 回答 2

3

Generally you need to tell git what you want to push where.

You can for example say:

git push origin HEAD:feature/blogs

This will push the current HEAD to feature/blogs on origin.

Then there are a few shorthands:

git push origin feature/blogs

This will look for a local branch "feature/blogs" and push it to origin as a branch with the same name.

If you simply say

git push

you do not specify what to push where. Hence git will have to "guess" what you mean. - In your case it just pushed all local branches to branches of the same name on origin.

You can specify what git shall do in this case by setting push.default. For example:

git config push.default current

will tell git to push only the current branch to a branch of the same name.

Have a look at git help config and look for push.default for other options.

Newer git versions default to push.default=simple, which will generally give you much better feedback.

于 2013-06-06T13:36:27.537 回答
0

当你在做的时候git push,git 会尝试推送所有有遥控器的分支。所以你确实成功 push feature/blogsdevelopment失败是因为你落后于那个遥控器。如果您git checkout development随后执行 a git pull,您应该获得该分支的更新。

git push origin feature/blogs只推一个分支。

由于您只是在尝试 push feature/blogs,因此无需担心此消息。除非推送失败的分支是feature/blogs

我相信这个功能在最新版本的 git 中正在发生变化。那样git push只会推动你所在的分支,而不是所有分支。

于 2013-06-06T13:20:41.737 回答