Git 推送错误:“![拒绝] 开发 -> 开发(非快进)”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24414854/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 10:08:47  来源:igfitidea点击:

Git push error: "! [rejected] develop -> develop (non-fast-forward)"

gitbitbucket

提问by Sray

I have a list of commits (newest first):

我有一个提交列表(最新的在前):

abcd4 message
abcd3 wrong commit message2
abcd2 wrong commit message1
abcd1 message

I need to change commit messages of abcd2and abcd3. I'm doing it the following way:

我需要改变提交的信息abcd2abcd3。我正在按以下方式进行操作:

rebase -i abcd1

Then, in interactive mode I replace pickwith reword, change the necessary commit messages and save the changes. Everything works fine here.

然后,在交互模式下,我替换pickreword,更改必要的提交消息并保存更改。这里一切正常。

The problem is the following: the branch is fully pushed to Bitbucket so there are wrong commit messages on Bitbucket as well.

问题如下:分支完全推送到 Bitbucket,因此 Bitbucket 上也有错误的提交消息。

I tried to push the changes but got the error:

我尝试推送更改但出现错误:

 ! [rejected]        develop -> develop (non-fast-forward)
error: failed to push some refs to 'https://[email protected]/user/repository.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.

I tried to pull the changes but got smth. weird after pull was accomplished:

我试图拉动更改,但得到了 smth。拉动完成后很奇怪:

git log --pretty=format:'%h %s' --graph
*   ccceeefff Merge branch 'develop' of https://bitbucket.org/user/repository into develop
|\  
| * abcd3 wrong commit message2
| * abcd2 wrong commit message1
* | new_hash_of_abcd3 new commit message2
* | new_hash_of_abcd2 new commit message1
|/  
* abcd1 message

So my question is: what is the correct way to change the messages in my case?

所以我的问题是:在我的案例中更改消息的正确方法是什么?

回答by jkyako

You should be able to force the push with (assuming you have bitbucket set up as the remote "origin"):

您应该能够强制推送(假设您已将 bitbucket 设置为远程“来源”):

git checkout develop
git push -f origin develop

Note that before you do that you may need to reset your local develop branch (if it's now pointing at your pulled/merged commit):

请注意,在执行此操作之前,您可能需要重置本地开发分支(如果它现在指向您的拉取/合并提交):

git checkout develop
git reset --hard new_hash_of_abcd3
git push -f origin develop