您好我使用以下命令成功删除了vile
提交:
git rebase -p 0df8fg5^ 0df8fg5
我正在master
分支机构工作。
但是现在当我:
git push
它给出了:
To git@github.com:my_user/my_repo.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'git@github.com:my_user/my_repo.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first merge the remote changes (e.g.,
hint: 'git pull') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
git status
给出:
$ git status
# On branch master
# Your branch and 'origin/master' have diverged,
# and have 2 and 3 different commits each, respectively.
# (use "git pull" to merge the remote branch into yours)
#
nothing to commit, working directory clean
答案 0 :(得分:3)
它说你已经与主人分道扬and了,因为它看起来好像有一个点,你有origin/master
没有提交,origin/master
有承诺你没有。这一点是您从master
的本地副本中删除提交的点(rebase会更改以下提交的sha)。
要解决此问题,您必须强制推送。 但默认情况下,推送将所有本地分支推送到远程中具有相同名称的分支,这意味着强制推送可能会覆盖其他人的更改。
您可以使用配置设置更改git的默认行为:
git config --global push.default <setting>
其中<setting>
可以是upstream
,current
或simple
,以防止推送到您拥有本地版本的所有分支。 Git 2之前的默认值是matching
,它具有我正在讨论的覆盖行为,而Git 2之后的默认行为是simple
。这是git man-page的一段摘录,描述了每个设置实际上做了什么:
current
- 推送当前分支以更新接收端具有相同名称的分支。适用于中央和非中央工作流程。
upstream
- 将当前分支推送回分支,该分支的更改通常集成到当前分支(称为@ {upstream})。如果您要推送到通常从中拉出的相同存储库(即中央工作流程),此模式才有意义。
simple
- 在集中式工作流程中,如果上游分支的名称与本地分支不同,则在上游工作时会增加安全性以拒绝推送。当推送到与您通常拉出的遥控器不同的遥控器时,请作为当前工作。这是最安全的选择,适合初学者。
此模式将成为Git 2.0中的默认模式。
强制推动的命令是:
git push -f
答案 1 :(得分:1)
你必须强制推动
git push -f
如果其他人也在使用远程主分支,这将给他们带来惊喜。不一定是积极的方式。
答案 2 :(得分:1)
经过重组后,你需要一般强行推进远程。
$ git push -f origin master:master
这样做会强制更新master而不关心快进