gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 13:26:42 25 4
gpt4 key购买 nike

在我们的 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 commit4bf31def Last good commit

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

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com