Git:删除 repo 中的所有文件然后回滚提交有任何长期影响吗?

标签 git

在我们的 git 仓库中,我们不小心做了一个删除我们所有文件的提交。此提交已推送到我们的中央服务器,并已被其他开发人员和构建服务器 pull 下,因此重写历史以撤消此操作并不理想。相反,我们进行了另一次回滚提交以将所有文件恢复到它们之前的状态,并在其间进行了另一次尝试的回滚提交,但不知何故只恢复了一些文件。

cc043989 Rollback commit (goes back to 4bf31def)
f5d7f10e Failed rollback commit
cd60376f Delete all files commit
4bf31def Last good commit
.
.
.

我们担心这是否会导致任何长期影响,特别是关于 merge 到/从功能分支和到/从子树 repo 。如果将来要不断进行 merge 或其他更具挑战性的事情,可能值得重写历史并手动处理构建服务器/其他开发人员存储库。

最佳答案

假设你的历史是这样的:

A --- B --- C --- D   master
 \
  E --- F             topic

In commit "B", you accidentally delete all files. In commit "C", you restore all files.

When you merge the topic branch into the master branch, you will get many more merge conflicts than you would get otherwise. I suggest rewriting history as if the files were never deleted, since there is no real benefit to keeping that commit around (unless it's a very public branch).

To delete the commits,

git checkout master
git rebase -i 4bf31def

然后注释掉错误的提交:

# cc043989 Rollback commit (goes back to 4bf31def)
# f5d7f10e Failed rollback commit
# cd60376f Delete all files commit
4bf31def Last good commit

好消息是您可以慢慢来。您可以稍后继续工作并修复历史记录,也可以现在修复它。

关于Git:删除 repo 中的所有文件然后回滚提交有任何长期影响吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14491571/

相关文章:

git - "integration branch"的目的是什么?

c++ - 如何组织 git 工作流以同时修复错误和引入新功能

windows - Windows 用户的 Git CRLF

git - 有人派我去 pull 他的变化。但是我无法将我的名字添加到该提交中

git - 我可以使用 Git 将更新补丁应用于定制软件吗?

android - 是否可以同时将文件添加到多个 git 仓库?

javascript - 你如何解决 yarn.lock 中的 Git 冲突

eclipse - 在Eclipse中使用EGit推送到远程Git repo时,我应该选择什么?

git - 如何在 bamboo 构建过程中只 check out git 存储库的一部分?

git - 这是在不使用 git merge 当前分支的情况下创建新分支的好方法吗?