与Gerrit一起使用时,如何为Git配置特定的上游push refspec? [英] How to configure specific upstream push refspec for Git when used with Gerrit?
问题描述
我使用 Gerrit代码审核设置Git,并正在寻找一种方法对于那些可能对Git来说是新手的用户来说,为必要的Git命令做一些必要的配置。
我现在用来启动一个新功能分支的命令本质上是(假设Gerrit是 origin
):
git checkout baseline
git pull
git checkout -b work1234
git push -u原始工作1234
这开始了一项新工作package work1234
从一些 baseline
分支,最后一个push在Gerrit中创建分支并设置上游。所以 .git / config
看起来像这样:
[branchwork1234 ]
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。< name>。*
- 似乎没有任何设置push refspec
push的特定选项。
远程。< name>< / code> ; .push
- 我在这里试过refs / heads / *:refs / for / *
,但是git push $在这种情况下,c $ c>始终要推送所有本地分支,而我只想要当前分支
如果我不能让Git自己做这个,我会写一个小的包装脚本来完全指定refspecs。然而,如果Git本能地推到正确的地方,那会更好。 我最终写了一个新的 git-submit
script:
#!/ bin / sh -e
如果[-z$ 1];然后
REMOTE =原产地
其他
REMOTE = $ 1
fi
BRANCH =`git symbolic-ref HEAD`
case $ BRANCH in
refs / heads / *)
BRANCH =`basename $ BRANCH`
;;
*)
echo我找不到你在哪个分支。
出口1
;;
esac
git push $ REMOTE HEAD:refs / for / $ BRANCH
我把这个脚本放在 / usr / local / libexec / git-core / git-submit
中,现在有一个命令提交新代码给Gerrit进行审查:
$ git submit
如果Gerrit不是 origin
remote,则视情况使用 git submit< remote>
。
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.
I ended up writing a new git-submit
script:
#!/bin/sh -e
if [ -z "$1" ]; then
REMOTE=origin
else
REMOTE=$1
fi
BRANCH=`git symbolic-ref HEAD`
case $BRANCH in
refs/heads/*)
BRANCH=`basename $BRANCH`
;;
*)
echo "I can't figure out which branch you are on."
exit 1
;;
esac
git push $REMOTE HEAD:refs/for/$BRANCH
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:
$ git submit
If Gerrit is not the origin
remote, then use git submit <remote>
as appropriate.
这篇关于与Gerrit一起使用时,如何为Git配置特定的上游push refspec?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!