如何删除 Github 和 Bitbucket 上 git 的提交

How to delete commits from git on Github and Bitbucket

我不小心从我的 Django 项目中的 .idea 目录中推送了我的 .gitignore 文件中的文件。我试图从我的 bitbucket 存储库中完全删除提交,因为我正在与其他人一起处理该项目,并且他无法在不影响他自己的 .idea 文件的情况下提取我的更改。我看到其他 SO 问题,他们说要使用 git 还原,但是我记得还有另一个命令,您可以在其中推送您所做的最后一次良好提交,之后的所有内容都从 master 分支中删除。例如

提交历史:

94ca48e

55fab05

3813803

我想删除 94ca48e 和 55fab05。我曾经找到一个命令,你可以使 3813803 成为最新的提交,并且在该提交之后远程存储库中的所有内容都将被删除,但我在任何地方都找不到它。

使用git reset --hard 3813803。此 无法撤消 并且在本地和远程都有效。

对于使用 git push --force origin master

的远程推送

查看 Atlassian here 的 git 文档。

让我也引用那里的话:

Whereas reverting is designed to safely undo a public commit, git reset is designed to undo local changes. Because of their distinct goals, the two commands are implemented differently: resetting completely removes a changeset, whereas reverting maintains the original changeset and uses a new commit to apply the undo.

不过,

git reset 是此处要使用的,因为您要求完全删除。

即使提交被硬重置,不需要的提交仍会显示在历史记录中。如果历史也需要重置,那么恐怕只有删除并重新创建分支才能做到这一点。