你好,我成功地使用以下命令删除了一个错误提交:
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
-f
强制推送,因为答案会告诉你。 - eckesgit revert
错误的单个提交。这会引入一个新的提交,撤消错误提交的更改,但不会从历史记录中删除错误提交。然后可以安全地推送此更改。 - eckes