HEAD 的 git 别名:refs/for/master
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7423893/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
git alias for HEAD:refs/for/master
提问by Macarse
I am configuring Gerrit
and I would like to avoid writing:
我正在配置Gerrit
,我想避免写:
git push gerrit HEAD:refs/for/master
I would like to write:
我想写:
git push review
I am sure it's possible modifying .git/config
but I can't make it work.
我确信可以修改,.git/config
但我不能让它工作。
回答by Alex Brown
I set up two different push types, review and noreview:
我设置了两种不同的推送类型,review 和 noreview:
for reviews:
评论:
git config remote.review.pushurl ssh://<GERRIT_HOST>:29418/<PROJECT_PATH>.git
git config remote.review.push refs/heads/*:refs/for/*
git push review # this will push your current branch up for review
to bypass review:
绕过:
git config remote.noreview.pushurl ssh://<GERRIT_HOST>:29418/<PROJECT_PATH>.git
git config remote.noreview.push refs/heads/*
git push noreview # this will push your current branch up, bypassing review
Note that there are some Gerrit Project changes that need to be made by the Project Owner/Gerrit Admin in order to bypass a review as well. I think the "Push" permission will need to be added to the project for refs/* (unless you're getting specific about what branch you'll allow bypassing the review in). However, for reviews, the permissions needed to post in will already be set up. In other words, if your
请注意,项目所有者/Gerrit 管理员也需要进行一些 Gerrit 项目更改以绕过。我认为需要将“推送”权限添加到 refs/* 的项目中(除非您具体说明允许绕过的分支)。但是,对于评论,已设置发布所需的权限。换句话说,如果你的
git push gerrit HEAD:refs/for/master
is working, than the "review" part above should work as well without changing anything else.
正在工作,比上面的“评论”部分也应该工作,而无需更改任何其他内容。
回答by Ben Madsen
What you're best off doing is a Git scriptlet in your alias. Something like this works based on the 'upstream' branch, although I'd like to clean this up a little bit still:
您最好做的是别名中的 Git 脚本。像这样的工作基于“上游”分支,尽管我想稍微清理一下:
~/.gitconfig
~/.gitconfig
[alias]
pub = "!f() { git push -u ${1:-origin} HEAD:`git config branch.$(git name-rev --name-only HEAD).merge | sed -e 's@refs/heads/@refs/for/@'`; }; f"
This way, you can simply type:
这样,您只需键入:
git pub
and it's just like you typed:
就像你输入的一样:
git push -u origin HEAD:refs/for/master
or
或者
git push -u origin HEAD:refs/for/myremote-branch
The only requirement for this is that it is only compatible with the Git Bash shell on Windows, or one of the many Linux shells.
唯一的要求是它只与 Windows 上的 Git Bash shell 或许多 Linux shell 之一兼容。
回答by Tomasz Wysocki
Why don't create bash alias?
为什么不创建 bash 别名?
alias review="git push gerrit HEAD:refs/for/master"
Now you can just type:
现在你可以输入:
review
If you want to work on morethan one gerrit branch, check my bash helpers for that: https://github.com/tomwys/gerrit-bash-commands
如果您想在多个gerrit 分支上工作,请查看我的 bash 助手:https: //github.com/tomwys/gerrit-bash-commands
回答by Dolph
You might also be interested in git-review, which not only eliminates the push
by simply providing for:
您可能还对git-review感兴趣,它不仅push
通过简单地提供以下内容来消除:
git review
... but also lets you do things like:
...但也可以让您执行以下操作:
git review branchname
Checkout the Usage section on the link above for more.
查看上面链接上的使用部分了解更多信息。
回答by Rafa?
And if you want to allow direct push to branch in refs/heads/ you simply add a right in gerrit web gui:
如果你想允许直接推送到 refs/heads/ 中的分支,你只需在 gerrit web gui 中添加一个权限:
- open project properties,
- pick access,
- Add Reference,
- refs/heads/*
- pick "Push"
- type group name,
- refs/heads/*
- save.
- 打开项目属性,
- 选择访问,
- 添加参考,
- 参考/负责人/*
- 选择“推”
- 输入组名,
- 参考/负责人/*
- 节省。
youre done.
你完成了。
回答by Ryan Stewart
Maybe not exactly what you're looking for, but if you:
也许不完全是你要找的,但如果你:
- Rename
gerrit
toreview
(withgit remote rename gerrit review
), git config push.default tracking
, andgit config branch.master.merge refs/for/master
,
- 重命名
gerrit
为review
(withgit remote rename gerrit review
), git config push.default tracking
, 和git config branch.master.merge refs/for/master
,
then you can git push review
, and your master will be pushed to refs/for/master
on gerrit.
那么你可以git push review
,你的主人将被推到refs/for/master
gerrit 上。
And, incidentally, if you git config branch.master.remote review
, then you can just git push
and get the same thing.
而且,顺便说一句,如果你git config branch.master.remote review
,那么你就可以git push
得到同样的东西。
回答by Szymon Sad?o
Those of you who want to push only to master branch through gerrit, add the following to .git\config
那些只想通过 gerrit 推送到 master 分支的人,将以下内容添加到 .git\config
[remote "review"]
push = HEAD:refs/for/master
pushurl = ssh://GERRIT_URL:29418/PROJECT_NAME
or execute in project dir
或在项目目录中执行
git config remote.review.push HEAD:refs/for/master
git config remote.review.pushurl ssh://GERRIT_URL:29418/PROJECT_NAME
Then you can use
然后你可以使用
git push review
to push to Gerrit. Using this method you can push from any of your local branches and the data will always go to master branch
推向 Gerrit。使用这种方法,您可以从任何本地分支推送数据,并且数据将始终转到 master 分支
回答by Alex
Hi just create a simple script to automate the process:
嗨,只需创建一个简单的脚本来自动化该过程:
#!/bin/bash
GROUP1_REVIEWER="group1 list of mail separated by space"
GROUP2_REVIEWER="group2 list of mail separated by space"
GROUP3_REVIEWER="group3 list of mail separated by space"
ORIGIN=$(git config --get remote.origin.url)
[ $? -ne 0 ] && echo "Git repo not found; EXIT" && exit 1
case in
group1) REVIEWER_LIST=$GROUP1_REVIEWER ;;
group2) REVIEWER_LIST=$GROUP2_REVIEWER ;;
group3) REVIEWER_LIST=$GROUP3_REVIEWER ;;
*) echo "Please specify one existent group"; exit 1 ;;
esac
[ "" == "" ] && echo "Please specify one existent group" && exit 1
pushurl=${ORIGIN}
push="HEAD:refs/for/master"
receivepack="$(printf "git receive-pack "; for reviewer in $REVIEWER_LIST ; do printf -- "--reviewer $reviewer "; done)"
# check if review remote is already present
git config -l | grep remote.review 1>/dev/null 2>&1
[ $? -eq 0 ] && echo "Remote review already present; configure it manually; EXIT" && exit 1
# start config
echo "Adding new remote review config"
git config remote.review.pushurl $pushurl
git config remote.review.push $push
git config remote.review.receivepack "$receivepack"
You will the use as:
您将用作:
git_review_add_config.sh group1
And select the different group you need to configure.
并选择您需要配置的不同组。