[英]Push current branch to Gerrit
I like to use simply git push
to push (only) the current branch to the configured upstream.我喜欢简单地使用git push
将当前分支(仅) git push
送到配置的上游。 For that I set git config push.default upstream
which does exactly the right thing.为此,我设置了git config push.default upstream
,这完全正确。
Now I tried to set up aa suitable remote for Gerrit, which automatically pushes to refs/for/*
.现在我尝试为 Gerrit 设置一个合适的遥控器,它会自动推送到refs/for/*
。
The idea was doing it this way:这个想法是这样做的:
[remote "gerrit"]
url = ssh://host:port/repo
push = refs/heads/*:refs/for/*
I would like to type git push gerrit
and expect git to push only the current branch to the correct ref.我想输入git push gerrit
并期望 git 只将当前分支推送到正确的引用。
Unfortunately now git tries to push all local branches to Gerrit.不幸的是,现在 git 尝试将所有本地分支推送到 Gerrit。 - Is there any way to tell git to push only the current branch like with the push.default
above? - 有没有办法告诉 git 只推送当前分支,就像上面的push.default
一样?
Update:更新:
For Gerrit I need a refspec like 'branch:refs/for/branch' with branch being the current branch.对于 Gerrit,我需要一个像 'branch:refs/for/branch' 这样的 refspec,其中 branch 是当前分支。
Question:问题:
git push
automatically push to the correct refs/for ref?有没有办法配置 git 使普通的git push
自动推送到正确的 refs/for ref?Currently the best way I found is wrapping everything in a separate script like suggested here .目前我发现的最好方法是将所有内容包装在一个单独的脚本中,如建议的此处。 But I am still not convinced that it is not possible with just a suitable refspec.但我仍然不相信仅使用合适的 refspec 是不可能的。
According to the source , Git currently implements push.default = upstream
by generating an explicit refspec containing explicit names.根据来源,Git 目前通过生成包含显式名称的显式push.default = upstream
实现push.default = upstream
。
Seems like there is currently no way to specify that behavior by a single generic refspec, and some script (like suggested here ) which builds an explicit refspec is the only way for now.好像目前还没有办法通过一个通用的Refspec指定的行为,以及一些脚本(如建议在这里),它构建了一个明确的Refspec是唯一的办法现在。
As a workaround, I intercepted git function and get it to do the default push:作为一种解决方法,我拦截了 git 函数并让它执行默认推送:
.bashrc .bashrc
git ()
{
if [ $1 = "push" -a -z $2 ]
then
/usr/bin/git push origin HEAD:refs/for/master
else
/usr/bin/git $@
fi
}
I guess its a hack, but it works for me.我想这是一个黑客,但它对我有用。
You can configure git to send only the current branch to the remote repository with the command git config --global push.default current
.您可以使用命令git config --global push.default current
将git config --global push.default current
为仅将当前分支发送到远程存储库。
The other options that you can pass to push.default are:您可以传递给 push.default 的其他选项是:
nothing - do not push anything.
matching - push all matching branches. All branches having the same name in both ends are considered to be matching. This is the default.
upstream - push the current branch to its upstream branch.
tracking - deprecated synonym for upstream.
current - push the current branch to a branch of the same name.
These configurations can be seen in git help config
command.这些配置可以在git help config
命令中看到。
UPDATE: However, reading more carefully the manual page, push.default
"defines the action git push should take if no refspec is given on the command line, no refspec is configured in the remote, and no refspec is implied by any of the options given on the command line".更新:然而,更仔细地阅读手册页, push.default
“定义了 git push 应该采取的操作,如果命令行上没有给出push.default
,没有在远程配置push.default
,并且任何选项都没有暗示任何 refspec在命令行上给出”。 So, I think you will need to use the script to send only the current branch when specifying a refspec.因此,我认为在指定 refspec 时,您将需要使用脚本仅发送当前分支。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.