Git - 如何重置 "push"

Git - how to reset a "push"

不知何故,我有一个非常大的本地存储库,因为我不小心添加了超过 2 GB 的文件,并且没有考虑就试图推送它。我中止,删除文件并重新提交,但是当我尝试 git push origin master 到 Bitbucket 时,它失败了:

fatal: The remote end hung up unexpectedly

我的 .git 文件仍然很大,尽管我早就删除了不需要的文件。由于推送超过 2 GB,Bitbucket 说我需要将 http.postBuffer 设置为更高的数字。我已经这样做了很多次,但在尝试了大约 15 次之后,我想重新开始。

git status 给我这个:

On branch master
Your branch is ahead of 'origin/master' by 4 commits.
  (use "git push" to publish your local commits)

但由于推送始终无效,我该如何解决?最坏的情况我可以炸毁回购并重建它,但我想知道是否有重置推送的方法,因为它一直失败。

你可以通过 git reset

git reset --hard <commit-id>

您可以使用 git log

获取 commit-id

您将丢失 HEAD 和您选择的提交之间的所有工作

will help when the problematic commit is the most recent one, in other cases you’ll need to rewrite the history。我更喜欢 interactive rebase.

git rebase -i <some-commit-before-the-problematic-one>

它将按原样显示提交列表以及默认操作 pick。如果您想保留一部分有问题的提交,请将该行的 pick 更改为 edit。如果您想完全删除它,只需删除该行即可。如果您选择编辑该提交,Git 会将工作树置于您刚刚完成有问题的提交时的状态。更改您需要的内容并修改提交:

git commit --amend

之后,让Git使用

完成变基
git rebase --continue