gpt4 book ai didi

git - 获取错误 "Updates were rejected because the tip of your current branch is behind"

转载 作者:太空狗 更新时间:2023-10-29 13:55:24 26 4
gpt4 key购买 nike

我的本​​地系统代码已与 Bitbucket 的远程系统同步,但出现了一些问题,因此我通过运行 git reset --hard HEAD^ 删除了最后一次提交。之后我做了一些更改并提交了这些更改。现在,当我尝试将这些更改推送到远程时,我收到以下消息:

[vagrant@localhost horizon]$ 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

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)

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

我的问题是,在这种情况下我该如何推送?请解释。

最佳答案

您执行了以下命令:

 git reset --hard HEAD^

结果是历史重写。想象一下本地和远程的以下历史记录:

本地

A->B->C->D

远程

A->B->C->D

现在

git reset --hard HEAD^

一些哈希将被重写例如:

本地

A1->B1->C1->D1

远程

A->B->C->D

因此您的历史与远程历史不同。这意味着对于 git,你需要 merge 。那么,您的下一个问题将是:如何才能摆脱这种情况?很高兴你问:

<强>1。注意:永远不要重置历史并尝试推送,尤其是当你推送 --force 时!

  • 重置历史很好,如果你知道你在做什么。

一个可能的解决方案是还原您首先重置的提交并推送此还原的提交。但是为此你需要取回你用 git reset 重置的“糟糕的提交”。您可以通过 git reflog 执行此操作并从那里提取提交 SHA-1 并重置为此提交。然后你就处于提交之前的状态。之后,你执行 git reset HEAD^ 就安全了!

关于git - 获取错误 "Updates were rejected because the tip of your current branch is behind",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31509324/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com