gpt4 book ai didi

git push -> 仅代码审查当前更改(remote.origin.push 覆盖 push.default)

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

我的团队正在使用 gerrit 代码审查,本质上这意味着默认的推送行为会绕过标准工作流程,因此我们需要使用 git push origin HEAD:refs/for/feature 来正确推送我们的代码获得审核。

默认的推送行为如下所示:

user$ git push --dry-run
To https://gerrit.company.url/project
83fa2a5..aca3a22 feature -> feature

这会绕过不需要的审核过程。

当我将推送引用规范 ( reference here ) 设置为 refs/heads/*:refs/for/* 时,这朝着正确的方向迈出了一步:

user $ git config remote.origin.push refs/heads/*:refs/for/*
user$ git push --dry-run
To https://gerrit.company.url/project
* [new branch] master -> refs/for/master
* [new branch] old_stuff -> refs/for/old_stuff
* [new branch] feature -> refs/for/feature

现在它正试图将 feature 推送到 refs/for/feature,这是我想要的,但它也在尝试将我所有的分支推送到原点。 Gerrit 拒绝了多个请求,因此我得到如下输出:

user$ git push
....
To https://gerrit.company.url/project
! [remote rejected] master -> refs/for/master (no new changes)
! [remote rejected] old_stuff -> refs/for/old_stuff (duplicate request)
! [remote rejected] feature -> refs/for/feature (duplicate request)

但我发现,如果我命名当前分支,它会执行我期望的操作:

user $ git push origin feature --dry-run
To https://gerrit.company.url/project
* [new branch] feature -> refs/for/feature

这很好,我将能够使用它,但我想缩小它的范围。我想如果我将 push.default 设置为 current 这将意味着 git push 只会以这种方式推送当前分支,但对我来说失望:

user$ git config push.default current
user$ git push origin --dry-run
To https://gerrit.company.url/project
* [new branch] master -> refs/for/master
* [new branch] old_stuff -> refs/for/old_stuff
* [new branch] feature -> refs/for/feature

这似乎忽略了 push.default 设置,来自 git config documentation :

push.default

Defines the action git push should take if no refspec is explicitly given

所以 remote.origin.push 配置被解释为显式引用规范?即使将默认推送行为设置为 nothing,它仍然会尝试推送所有分支:

user$ git config push.default nothing
user$ git push
fatal: You didn't specify any refspecs to push, and push.default is "nothing".
user$ git config remote.origin.push refs/heads/*:refs/for/*
user$ git push origin --dry-run
To https://gerrit.company.url/project
* [new branch] master -> refs/for/master
* [new branch] old_stuff -> refs/for/old_stuff
* [new branch] feature -> refs/for/feature

我在这里错过了什么?如何让 git push 只推送当前分支,如 feature -> refs/for/feature

最佳答案

我不相信你想做的事目前只用 git 是做不到的。

我已经能够通过在我的配置文件中定义远程服务器别名来将它进一步缩小一级,如下所示,一个用于我可能想要推送的每个分支,但这显然是乏味和令人讨厌的,我仍然必须输入类似 git push masterrev 的内容。

    [remote "origin"]
url = ssh://gerritserver/product
fetch = +refs/heads/*:refs/remotes/origin/*
[remote "masterrev"]
url = ssh://gerritserver/product
fetch = +refs/heads/*:refs/remotes/origin/*
push = HEAD:refs/for/master

我知道提供您最初目标的唯一等价物是使用第 3 方工具,如 git-review OpenStack 开发人员组合起来供自己使用的工具。如果您的团队计划使用 Gerrit,这可能是值得的,因为它提供了其他功能,例如轻松访问精选或检查评论。

顺便说一句,我相信“当前”的 push.default 设置意味着假设本地分支名称应该通过 remote.*.push 修改推送,即使它们还不知道存在于服务器上。它不限制将哪些分支推送到“当前”分支,而是使用“当前”名称。

关于git push -> 仅代码审查当前更改(remote.origin.push 覆盖 push.default),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52878281/

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