Git 在没有良好初始提交的情况下擦除远程分支历史记录

Git 在没有良好初始提交的情况下擦除远程分支历史记录,git,Git,我有两个本地回购协议:a-public-project和top secret,在对这两个本地回购协议进行多次提交后,我在GitHub上创建了一个新的空回购协议,它将是a-public-project的远程回购协议,但我不小心推了top secret: cd C:/Git/top-secret git remote add github https://github.com/me/a-public-project.git git push -u github master 在恐慌模式下,我在线搜

我有两个本地回购协议:
a-public-project
top secret
,在对这两个本地回购协议进行多次提交后,我在GitHub上创建了一个新的空回购协议,它将是
a-public-project
的远程回购协议,但我不小心推了
top secret

cd C:/Git/top-secret
git remote add github https://github.com/me/a-public-project.git
git push -u github master
在恐慌模式下,我在线搜索并发现以下结果:

不幸的是,所有这些都涉及重置我的本地分支和执行git push--force:这假设有一个好的有意提交,我可以回滚到它。在这种情况下,我没有-整个回购历史记录都不好,远程回购需要删除其历史记录(但我的本地回购历史记录显然未被触及)


幸运的是,在这个特定的实例中,我能够使用GitHub网站删除repo,然后推送正确的本地repo,但是如果我无法控制的repo再次发生这种情况,我该怎么办?

一种快速恢复的方法是从远程删除主分支

git push github :master
或者您可以快速跳到
a-public-project
并强制将其覆盖

cd C:/Git/a-public-project
git remote add github https://github.com/me/a-public-project.git
git push -u github master --force

我在这里看到冒号的意义: