git 为什么 Gerrit 无法自行创建分支?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20606359/
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
Why Gerrit is unable to create branch by itself?
提问by trejder
Following this answerand my own question, I have a simple (hope so) question.
按照这个答案和我自己的问题,我有一个简单的(希望如此)问题。
If I'm pushing a particular branch, with all required refs properly set:
如果我正在推送一个特定的分支,并正确设置所有必需的引用:
git checkout 82-blah-blah
git push origin HEAD:refs/for/82-blah-blah
Why do I always get:
为什么我总是得到:
! [remote rejected] HEAD -> refs/for/82-blah-blah (branch 82-blah-blah not found)
and I always have to go to Gerrit's UI and create that branch manually?
我总是必须转到 Gerrit 的 UI 并手动创建该分支?
Isn't that an obvious step, that Gerrit could simply automate? Or am I missing something?
这不是一个明显的步骤,Gerrit 可以简单地自动化吗?或者我错过了什么?
采纳答案by mvp
This feature was implementedvery recently and will be available in Gerrit v2.9.
这个特性是最近实现的,将在Gerrit v2.9 中可用。
回答by uncletall
The accepted answer is referring to a feature that allows users to create branching using SSH, all it adds is the CreateBranchCommand. The original issue requestmight actually refer to what @trejder wants but the implementation is just a create branch through an SSH command.
接受的答案是指允许用户使用 SSH 创建分支的功能,它添加的只是CreateBranchCommand。最初的问题请求实际上可能是指@trejder 想要什么,但实现只是通过 SSH 命令创建的分支。
I was under the impression that if you have the create-reference right you can push to ref/for/new-branch but I was wrong, just tested it and it doesn't work. It only allows you to create new branches but directly pushing to them.
我的印象是,如果您拥有创建引用权限,您可以推送到 ref/for/new-branch,但我错了,只是对其进行了测试,但它不起作用。它只允许您创建新分支但直接推送到它们。
Guess the fastest way to get it done is:
猜猜完成它的最快方法是:
git checkout master
git push origin HEAD:new-branch
git checkout new-branch
git push origin HEAD:/refs/for/new-branch
回答by kalaivani
Use this simple bash script to create and push a new branch to gerrit. Usage: Branch_name and CommitId are 2 inputs needed
使用这个简单的 bash 脚本创建一个新分支并将其推送到 gerrit。用法:Branch_name 和 CommitId 是需要的 2 个输入
#!/bin/bash
read -p "Enter New Branch Name: " Branch_Name
read -p "Enter CommitID:" CommitID
git fetch --all
git branch $Branch_Name $CommitID
git push origin $Branch_Name:$Branch_Name
git checkout $Branch_Name
git branch --set-upstream-to=origin/$Branch_Name $Branch_Name
回答by panayot_kulchev_bg
Let say new branch is "myNewBranch"
假设新分支是“myNewBranch”
git checkout master
git push origin HEAD:myNewBranch
After commit some changes to push the new commit:
在提交一些更改以推送新提交后:
git push origin myNewBranch
Works for me. But..
对我来说有效。但..
Do not know why can not push the same commit to master after that and the other way around - if I have opened PR for review in master, can not push the same commit to the "myNewBranch". To do it had to abandon the PR to master and then cherry-pick the commit to the new local branch and then push to the remote "myNewBranch"
不知道为什么不能在此之后将相同的提交推送到 master,反之亦然 - 如果我在 master 中打开了 PR 进行,则不能将相同的提交推送到“myNewBranch”。要做到这一点,必须放弃 PR 来掌握,然后挑选提交到新的本地分支,然后推送到远程“myNewBranch”
Good luck!
祝你好运!