简体   繁体   English

git non-fast-forward被上游拒绝

[英]git non-fast-forward rejected with upstream

I have a git repo with a master that is set up in upstream, and a dev branch which is getting every stream from this master. 我有一个git repo,其中有一个上游设置的master,还有一个dev分支,该分支从该master获取每个流。

I have some commited changes on my dev branch that are useful only for this specific branch and not for the master, and I 我在我的dev分支上做了一些提交的更改,这些更改仅对特定分支有用,对master没有帮助,我

my current branch is : 我当前的分支是:

git status
On branch dev
Your branch is ahead of 'master' by 2 commits.

my commits are visible when I do 当我这样做时,我的提交是可见的

git diff origin/master..HEAD

my branch is up to date ( and goes through master as it was doing before) : 我的分支是最新的(并且像以前一样通过master):

git pull
From .
 * branch            master     -> FETCH_HEAD
Already up-to-date.

But when I push, I got bashed : 但是,当我推动时,我就感到沮丧:

git push origin
To https://my_git.git
 ! [rejected]        dev -> dev (non-fast-forward)
error: failed to push some refs to 'https://my_git.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

Any tips would be appreciated, I had a look on several posts like this : git push rejected non-fast-forward or this Git non-fast-forward rejected , but none of them seems to work in my case. 任何提示都将不胜感激,我看了几篇类似的文章: git push拒绝了非快进Git拒绝了非快进 ,但是在我看来,这些都不起作用。

Thanks 谢谢

Your problem is here: 您的问题在这里:

git push origin 

You did not specify any branch to push. 您未指定要推送的任何分支。
Assuming you are using git <2.0 you must set the branches that you wish to pull/push . 假设您正在使用git <2.0,则必须设置要pull/push的分支。 In your case its trying to push ALL your branches and one of them generate the error. 在您的情况下,它尝试推送所有分支,其中一个分支会生成错误。

This will for it for you 这会为你

# get all latest changes from the remote
git fetch --all

# merge the changes to the local repository
git pull origin dev 

# push the changes to the remote
git push origin dev

Git v2.0 Release Notes Git v2.0发行说明

Backward compatibility notes 向后兼容性说明

When "git push [$there]" does not say what to push, we have used the traditional "matching" semantics so far (all your branches were sent to the remote as long as there already are branches of the same name over there). 当“ git push [$ there]”没有说明要推送什么时,到目前为止,我们已经使用了传统的“匹配”语义(只要您的分支已经发送到远程,只要那里已经有同名的分支)即可。 。

In Git 2.0, the default is now the "simple" semantics, which pushes: 在Git 2.0中,默认值现在是“简单”语义,它推送:

  • only the current branch to the branch with the same name, and only when the current branch is set to integrate with that remote branch, if you are pushing to the same remote as you fetch from; 仅当当前分支设置为与该远程分支集成时,才可以将当前分支转移到具有相同名称的分支; or 要么

  • only the current branch to the branch with the same name, if you are pushing to a remote that is not where you usually fetch from. 如果要推送到通常不是从那里获取的远程站点,则仅将当前分支转移到同名分支。

You can use the configuration variable "push.default" to change this. 您可以使用配置变量“ push.default”进行更改。 If you are an old-timer who wants to keep using the "matching" semantics, you can set the variable to "matching", for example. 例如,如果您想继续使用“匹配”语义,可以将变量设置为“匹配”。 Read the documentation for other possibilities. 阅读文档以了解其他可能性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM