【发布时间】:2016-11-15 10:39:34
【问题描述】:
我有两个本地存储库:a-public-project 和 top-secret,在对两个本地存储库进行了多次提交之后,我在 GitHub 上创建了一个新的空存储库,它将作为 a-public-project 的远程存储库,但是我不小心推送了 @987654328 @ 改为:
cd C:/Git/top-secret
git remote add github https://github.com/me/a-public-project.git
git push -u github master
在恐慌模式下,我在网上搜索,发现了这些结果:
- Undoing a 'git push'
- Git: permanently remove few commits from remote branch
- Is there a way to rollback my last push to Git?
- http://christoph.ruegg.name/blog/git-howto-revert-a-commit-already-pushed-to-a-remote-reposit.htmlbranch
不幸的是,所有这些都涉及重置我的本地分支并执行git push --force:这假设我可以回滚到一个好的故意提交。在这种情况下,我不会 - 整个 repo 历史记录都很糟糕,remote repo 需要删除它的历史记录(但我的本地 repo 历史记录显然没有受到影响)。
幸运的是,在这个特定的例子中,我能够使用 GitHub 网站删除存储库,然后推送正确的本地存储库,但是如果我无法控制的存储库再次发生这种情况,我该怎么办?
【问题讨论】:
标签: git