HEAD 的 git 别名:refs/for/master

发布于 2024-12-04 12:36:54 字数 210 浏览 1 评论 0原文

我正在配置 Gerrit 并且我想避免写:

git push gerrit HEAD:refs/for/master

我想写:

git push review

我确信可以修改 .git/config 但我无法让它工作。

I am configuring Gerrit and I would like to avoid writing:

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

触ぅ动初心 2024-12-11 12:36:55

您可能还对 git-review 感兴趣,它不仅消除了 push 只需提供:

git review

... 但也可以让您执行以下操作:

git review branchname

查看上面链接上的“使用”部分以了解更多信息。

You might also be interested in git-review, which not only eliminates the push by simply providing for:

git review

... but also lets you do things like:

git review branchname

Checkout the Usage section on the link above for more.

美胚控场 2024-12-11 12:36:55

也许不是您要寻找的内容,但是如果您:

  1. 重命名gerrit 评论(使用git Remote Rename Rename gerrit评论),
  2. git config push.default跟踪
  3. git config branch.master.merge refs/for/master

然后您可以git push push评论和您的主将在Gerrit上推到refs/for/master

而且,顺便说一句,如果您git config branch.master.master.remote评论,则可以git push并获得相同的东西。

Maybe not exactly what you're looking for, but if you:

  1. Rename gerrit to review (with git remote rename gerrit review),
  2. git config push.default tracking, and
  3. 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.

And, incidentally, if you git config branch.master.remote review, then you can just git push and get the same thing.

人生百味 2024-12-11 12:36:55

如果您想允许直接推送到 refs/heads/ 中的分支,您只需在 gerrit web gui 中添加一个权限:

  1. 打开项目属性,
  2. 选择访问权限,
  3. 添加引用,
  4. refs/heads/*
  5. 选择“推送”
  6. 类型组名称,
  7. refs/头/*
  8. 保存。

你完成了。

And if you want to allow direct push to branch in refs/heads/ you simply add a right in gerrit web gui:

  1. open project properties,
  2. pick access,
  3. Add Reference,
  4. refs/heads/*
  5. pick "Push"
  6. type group name,
  7. refs/heads/*
  8. save.

youre done.

慈悲佛祖 2024-12-11 12:36:55

如果您只想通过 gerrit 推送到 master 分支,请将以下内容添加到 .git\config

[remote "review"]                                                        
    push = HEAD:refs/for/master                 
    pushurl = ssh://GERRIT_URL:29418/PROJECT_NAME

或在项目目录中执行,

git config remote.review.push HEAD:refs/for/master
git config remote.review.pushurl ssh://GERRIT_URL:29418/PROJECT_NAME

然后您就可以使用

git push review

推送到 Gerrit。使用此方法,您可以从任何本地分支推送,并且数据将始终发送到主分支

Those of you who want to push only to master branch through gerrit, add the following to .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

彻夜缠绵 2024-12-11 12:36:55

您好,只需创建一个简单的脚本来自动化该过程:

   #!/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 $1 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

   [ "$1" == "" ] && 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"

您将使用为:

git_review_add_config.sh group1

并选择您需要配置的不同组。

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 $1 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

   [ "$1" == "" ] && 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.

≈。彩虹 2024-12-11 12:36:54

我设置了两种不同的推送类型,review 和 noreview:

用于审核:

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

绕过审核:

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

请注意,项目所有者/Gerrit 管理员需要进行一些 Gerrit 项目更改才能绕过审核。我认为需要将“推送”权限添加到 refs/* 的项目中(除非您具体了解允许绕过审查的分支)。但是,对于评论,发布所需的权限已经设置好。换句话说,如果您

git push gerrit HEAD:refs/for/master

正在工作,那么上面的“审查”部分也应该可以工作,而无需更改任何其他内容。

I set up two different push types, review and 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

git push gerrit HEAD:refs/for/master

is working, than the "review" part above should work as well without changing anything else.

缘字诀 2024-12-11 12:36:54

你最好做的就是在你的别名中添​​加一个 Git scriptlet。类似这样的东西基于“上游”分支工作,尽管我想稍微清理一下:

~/.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"

这样,您可以简单地键入:

git pub

,就像您键入的一样:

git push -u origin HEAD:refs/for/master

git push -u origin HEAD:refs/for/myremote-branch

的唯一要求这是因为它仅与 Windows 上的 Git Bash shell 或众多 Linux shell 之一兼容。

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:

~/.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.

生来就爱笑 2024-12-11 12:36:54

为什么不创建 bash 别名?

alias review="git push gerrit HEAD:refs/for/master"

现在您只需输入:

review

如果您想在多个多个 gerrit 分支上工作,请检查我的 bash 助手:https://github.com/tomwys/gerrit-bash-commands

Why don't create bash alias?

alias review="git push gerrit HEAD:refs/for/master"

Now you can just type:

review

If you want to work on more than one gerrit branch, check my bash helpers for that: https://github.com/tomwys/gerrit-bash-commands

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文