git - I accidently deleted everything in a remote repository, and force rewrote history
问题描述
I pushed a commit on a remote repository where I changed one file, but the whole directory of the file was tracked in that commit, so it made it look like I changed every file in this directory.
So, I wanted to erase that commit from the history of the remote repo, with the command git push origin +f2d3f909138e785b63415808c487abc070c4a12b^:master, f2d3f909138e785b63415808c487abc070c4a12b being the commit I wanted to get rid of.
What happened is that every other commits in the history of the remote repo got deleted.
I'd just like to go back to way things were before that last command, the commit is not that much of a problem now. Worse case, I have a copy of the files locally, but the history held a lot of important information still.
解决方案
在您进行强制推进之前,您的团队中应该有一个人最后推进。该人在他/她的本地仓库中拥有所有提交。所以只需要求那个人将最新的提交推送到 origin/master 中:
git push -f origin [commit hash]:refs/heads/master
如果提交是未知的,因为该人获取了最新的更改并覆盖了他的本地分支,那么他可以git reflog
用来查找以前签出的提交。
或者,如果您有一个由推送触发的构建服务器(我希望您这样做),您可以在构建日志中找到最新的提交哈希。此外 - 该提交可能仍在 CI 作业的工作目录中。
推荐阅读
- bash - 如何让 bash 脚本在功能键按下时返回 true(用作 Sylpheed 过滤器)
- java - 在 java 中保存和加载不是字符串或 int 的对象
- azure - 运行 Docker 的 Azure 虚拟机上的“挂载:权限被拒绝”
- javascript - 让firebase返回一个排序的响应
- haskell - vim haskell 的符号和在 Haskell 中实现 SKI 的函数
- email-attachments - 如何通过 mailx 将标准输出作为附件发送?
- java - Spring Data MongoDB *在*保存到存储库后执行验证
- pimcore-v5 - 如何在 Pimcore v5 中设置 2 个相同类型的数据对象之间的父子关系?
- reactjs - 如何在本机反应中订购数组?
- docker - 在 Helm 图表 values.yaml 中拉取 docker hub 图像