当我们考虑在工作中从 SVN 迁移到 git 时,一位同事提出了一个问题,即恶意或容易发生事故的开发人员可能会使用 git rebase
从我们的共享存储库中删除远程历史记录。
编辑:正如答案中所指出的,也可以使用 git push origin :branch-name
从远程仓库中删除整个分支。
这是一个现实问题吗?如果是这样,我们可以采取什么方法来防止它?
最佳答案
我倾向于同意您同事的看法,这里存在问题,因为:
- 无论您多么信任您的提交者,人为错误的可能性始终存在
- 更繁琐的审核流程(例如 Gerrit)并不总是合适的
- 从备份中恢复可能会很慢而且像 PITA
您是否考虑过 receive.denyNonFastForwards
和 receive.denyDeletes
配置参数? AFAICT 这些在 Git 1.6 及更高版本中可用。
来自 Pro Git:
If you rebase commits that you’ve already pushed and then try to push again, or otherwise try to push a commit to a remote branch that doesn’t contain the commit that the remote branch currently points to, you’ll be denied. This is generally good policy; but in the case of the rebase, you may determine that you know what you’re doing and can force-update the remote branch with a
-f
flag to your push command.To disable the ability to force-update remote branches to non-fast-forward references, set
receive.denyNonFastForwards
The other way you can do this is via server-side receive hooks, which I’ll cover in a bit. That approach lets you do more complex things like deny non-fast-forwards to a certain subset of users.
正如作者所提到的,此规则也可以通过接收 Hook (即 described later in Pro Git)来执行。
这些技术应该可以防止意外(或恶意)丢失共享存储库中的历史记录。
关于git - git rebase 可以完全删除远程历史记录吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6704602/