git - 如何在gerrit上重写历史?

标签 git gerrit

Gerrit 不小心引入了一些 merge 提交(配置了“必要时 merge ”选项),我想将它们从历史记录中删除。 我知道团队使用 Git 时重写历史的缺陷,但在我们的案例中,开发人员不会受此影响,因为他们都没有在这个特定存储库中进行本地更改。

我在本地执行了 git rebase -i,Git 自动删除了 Gerrit 的 merge 提交。 我小心地删除了每个提交消息中以前的 Gerrit Change-Id,并且 Gerrit 提交消息 Hook 添加了新的。

git status 命令输出:

On branch master Your branch and 'origin/master' have diverged, and have 7 and 9 different commits each, respectively. (use "git pull" to merge the remote branch into yours) nothing to commit, working directory clean

这就是我想要的(9 次提交减去 2 次 merge 提交)。

当我尝试使用 git push origin HEAD:refs/for/master 推送 Gerrit 时,我没有收到任何错误。 但是,当我尝试在 Gerrit Web 界面上审查和提交时,出现以下错误:

The change could not be merged due to a path conflict. Please rebase the change locally and upload the rebased commit for review.

我做错了什么?

最佳答案

当重写历史时,你不会推送审查(不要推送到refs/for/*)。您需要直接推送到原始存储库 (refs/heads/*)。这意味着您将需要绕过 Gerrit 审查的权限。我建议您暂时授予自己权限,并在完成后删除它们,这样您以后就不会不小心绕过审核。

您还需要使用 -f 标志运行 git push 以告诉 git 重写历史记录。

关于git - 如何在gerrit上重写历史?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17338949/

相关文章:

git - 尝试推送到服务器时,netbeans 中出现 REJECTED_NONFASTFORWARD

git - 如何从我的 Github 配置文件中删除 fork 的项目

git - Gerrit - 如何禁止直接推送到 "master"但允许其他分支

gerrit - 如何在gerrit中获取以前的补丁

apache - 使用 http 身份验证设置 gerrit

git - 当我有写访问权限时,fork repo 有什么好处吗?

git - 为什么 Visual Studio 2015 中的 "Create Pull Request"菜单项总是被禁用?

git - 如何在 Gerrit 中创建一个新的补丁集?

prolog - 如果标签大于 0,Gerrit 允许提交(序言规则)

Git 作者未知