恢复并删除 Azure DevOps 提交历史记录?

问题描述 投票:0回答:1

我做了一个小提交,并将其推送到我们在 Azure DevOps 中的主分支。我意识到这个提交已经过时了,因为它是基于错误的假设和与我的同事的沟通不畅,而我的同事对 main 做了最后一次提交。

但是,我决定通过拉取请求恢复我的提交,但我一定做错了。我恢复了该恢复,并且基本上回到了原始提交的状态 - 在下一步中我将再次恢复(这次“正确”)。

因此,之后主分支中的代码库和所有文件都会很好,只是我们的 Azure DevOps 历史看起来相当“混乱”。例如。提交行(用线和点表示提交的图形表示)。

我很清楚使用 Git 的目的之一是完全透明,但我们是一个小团队,沟通非常开放并一致同意,如果可能的话,我们希望摆脱我的那个小“间奏曲”,如果可能的话.

有什么办法可以实现这个目标吗?

git azure azure-devops
1个回答
0
投票

要从提交历史记录中删除一个或多个提交,您可以使用

git reset --hard
git rebase --interactive
,然后 push force 到远程存储库。

在第一种情况下,您可以将存储库重置为特定提交,删除最后 n 次提交。在你的情况下,最后三个提交。

# resetting to the third to last commit
git reset --hard my_branch~3

# or alternatively, resetting to a specific commit with its SHA1
git reset --hard <SHA1-third-to-last-commit>

# aligning the remote's branch' history and tip to the local branch
git push --force

在第二种情况下,您可以执行交互式变基,其中您将删除最后三个提交。

# make sure to be on the right branch
git checkout my_branch

# starting the interactive rebase
git rebase --interactive

# aligning the remote's branch' history and tip to the local branch
git push --force

警告:作为一般规则,在强制推送之前,请确保所有开发人员都知道您正在重写分支的历史记录,并且他们的任何工作都不是基于已删除的提交。

© www.soinside.com 2019 - 2024. All rights reserved.