与 Gerrit 一起使用时如何为 Git 配置特定的上游推送引用规范?
我正在使用 Gerrit Code Review 设置 Git,并正在寻找一种方法来进行必要的操作对于 Git 新手来说,Git 命令相对简单。
我目前用于启动新功能分支的命令本质上是(假设 Gerrit 是origin
):
git checkout baseline
git pull
git checkout -b work1234
git push -u origin work1234
这将启动一个从某些基线
分支的新工作包work1234
code>,最后的推送在 Gerrit 中创建分支并设置上游。所以 .git/config
看起来像这样:
[branch "work1234"]
remote = origin
merge = refs/heads/work1234
现在,Gerrit 希望将新提交的审核推送到特殊的 refspec,例如 refs/for/work1234
。我可以手动执行此操作:
git push origin work1234:refs/for/work1234
我想做的是找到某种方法来设置 .git/config
,以便简单的 git Push
将当前分支推送到Gerrit 需要的遥控器上的 refspec。我查看了以下 git config 区域:
- .
.* 似乎没有任何用于设置推送引用规范的特定选项 - branch Push.default - 我有点想要这里的
上游
remote.
- 我尝试过.push refs/heads/*:refs/for/*
这里但是git push
在这种情况下总是想推送所有本地分支,而我只是想要当前分支
如果我不能让 Git 自己完成此操作,我将编写一个完整指定引用规范的小包装脚本。不过,如果 Git 能够原生推送到正确的位置就更好了。
I'm setting up Git with Gerrit Code Review and am looking for a way to make the necessary Git commands relatively straightforward for users who might be new to Git.
The commands I currently have for starting a new feature branch are essentially (assuming Gerrit is origin
):
git checkout baseline
git pull
git checkout -b work1234
git push -u origin work1234
This starts a new work package work1234
branched from some baseline
, and the final push creates the branch in Gerrit and sets the upstream. So .git/config
looks something like:
[branch "work1234"]
remote = origin
merge = refs/heads/work1234
Now, Gerrit wants new commits for review to be pushed to a special refspec, refs/for/work1234
for example. I can do this manually with:
git push origin work1234:refs/for/work1234
What I would like to do is find some way to set up .git/config
so that a plain git push
will push the current branch to the refspec on the remote that Gerrit requires. I have looked at the following git config
areas:
branch.<name>.*
- doesn't seem to have any specific option for setting the push refspecpush.default
- I sort of wantupstream
hereremote.<name>.push
- I triedrefs/heads/*:refs/for/*
here butgit push
always wants to push all local branches in this case, while I just want the current branch
If I can't make Git do this by itself, I'll write a small wrapper script that fully specifies the refspecs. However, it would be better if Git could push to the right place natively.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我最终编写了一个新的 git-submit 脚本:
我将此脚本放在 /usr/local/libexec/git-core/git-submit 中,现在有一个命令可以执行向 Gerrit 提交新代码以供审核:
如果 Gerrit 不是
origin
远程,则根据需要使用git Submit
。I ended up writing a new
git-submit
script:I put this script in
/usr/local/libexec/git-core/git-submit
and now there's one command to submit new code to Gerrit for review:If Gerrit is not the
origin
remote, then usegit submit <remote>
as appropriate.我发现了两个选项:
1)查看我制作的项目,ggh: https://github.com/hobbs /ggh
2) 您可以在遥控器中配置默认的推送引用规范。我只弄清楚如何使用硬编码的远程分支来执行此操作,仍在尝试找出如何使用通配符远程引用规范,以便它始终推送到您正在跟踪的远程:
Two options I've found:
1) Check out a project I made, ggh: https://github.com/hobbs/ggh
2) You can configure the default push refspec in your remote. I've only figured out how to do this with a hardcoded remote branch, still trying to figure out how to wildcard the remote refspec so that it always pushes to the remote you're tracking:
这是 Greg Hewgill 答案的改进。
在路径上的某个位置创建一个脚本,例如在您的配置文件 bin 文件夹中(如果需要,即使在 Windows 上也创建一个脚本):
包含以下内容:
假设您创建一个远程跟踪分支,例如:
您可以简单地调用:
... 推送到在这种情况下,
refs/for/master
。Here is an improvement of Greg Hewgill answer.
Create a script somewhere on the path, like on your profile bin folder (create one if necessary, even on Windows):
With the following content:
Supposing you create a remote tracking branch like:
You can simply call:
... to push to
refs/for/master
in this case.或 .git/config:
我不确定是否有办法在任何地方放置通配符以使其适用于所有分支。
or .git/config:
I'm not sure if there's a way to put a wildcard in there anywhere to make it work for all branches.