git 使用 SourceTree 推送到 gerrit
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9917645/
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
Push to gerrit using SourceTree
提问by JoseM
I can't figure out how to make SourceTree push to Gerrit.
我不知道如何让 SourceTree 推送到 Gerrit。
I saw this link but I still don't understand how it can be done: https://answers.atlassian.com/questions/29361/configuring-sourcetree-push-for-gerrit
我看到了这个链接,但我仍然不明白它是如何完成的:https: //answers.atlassian.com/questions/29361/configuring-sourcetree-push-for-gerrit
Apparently according to the release notes for 1.3.3 there is a way to do it but I can't figure it out: http://www.sourcetreeapp.com/update/ReleaseNotes.html#version-1.3.3
显然根据 1.3.3 的发行说明,有一种方法可以做到,但我无法弄清楚:http: //www.sourcetreeapp.com/update/ReleaseNotes.html#version-1.3.3
Is there a step by step guide somewhere as to how to do it?
是否有关于如何做到这一点的分步指南?
Right now I run this command on the terminal to push
现在我在终端上运行这个命令来推送
git push origin HEAD:refs/for/master
回答by mozart27
I believe the answer provided by atlassian says to change the name of the remote branch when you see the Push dialog.
我相信 atlassian 提供的答案会在您看到 Push 对话框时更改远程分支的名称。
- Open the push dialog
- Click on the remote branch name under the "Remote Branch" column (mine is presently 'master')
- Type in the new remo branch name - which would be 'refs/for/master' for me
- Click OK.
- 打开推送对话框
- 单击“远程分支”列下的远程分支名称(我的当前是“master”)
- 输入新的 remo 分支名称 - 对我来说是 'refs/for/master'
- 单击确定。
This appears to have properly pushed the commits into Gerrit for me. The problem I have now is that the 'refs/for/master' value doesn't persist. Now to figure that out. I will update this post once I've figured that out. Hope this helps even tho it's late to the game.
这似乎为我正确地将提交推送到 Gerrit 中。我现在遇到的问题是“refs/for/master”值不存在。现在要弄清楚。一旦我弄清楚了,我会更新这篇文章。希望这会有所帮助,即使游戏已经晚了。
Update: it turns out that you need to add a push entry under remote origin in the .git/config. You should do this via the git config command (tho i did edit the file manually i'm sure that's bad practice). the push line i wrote is:
更新:事实证明,您需要在 .git/config 中的远程源下添加一个推送条目。您应该通过 git config 命令执行此操作(虽然我确实手动编辑了文件,但我确定这是不好的做法)。我写的推送线是:
push = refs/heads/*:refs/for/*
for clarity here is my remote origin entry in .git/config:
为清楚起见,这里是我在 .git/config 中的远程源条目:
[remote "origin"]
url = ssh://gerrit-test.example.com:29418/mystuff.git
fetch = +refs/heads/*:refs/remotes/origin/*
push = refs/heads/*:refs/for/*
In SourceTree you can now push and it will push to gerrit instead of the final repo. ( you can now also just do git push without specifying anything else and it will push to gerrit ). Note that after a push, SourceTree will still show a number on the Push button that says you still have stuff to push. This is because it is still fetching from the master repo and the changes you've pushed into gerrit have not yet been merged into the master repo. Once your changes have been merged into the master repo the number on the Push button will disappear.
在 SourceTree 中,您现在可以推送,它将推送到 gerrit 而不是最终存储库。(您现在也可以只执行 git push 而不指定任何其他内容,它将推送到 gerrit )。请注意,在推送后,SourceTree 仍会在“推送”按钮上显示一个数字,表示您仍有要推送的内容。这是因为它仍在从主存储库中获取,并且您推送到 gerrit 中的更改尚未合并到主存储库中。一旦您的更改合并到主存储库中,Push 按钮上的数字就会消失。
回答by Jonas Bang Christensen
If you have a setup with Git Flow (http://nvie.com/posts/a-successful-git-branching-model/), or similar, you often want to push your local branch to a different remote branch. In such a case the generic push rule (mentioned by mozart27) will not work as it always pushes your local branch to the corresponding remote branch.
如果您有 Git Flow ( http://nvie.com/posts/a-successful-git-branching-model/) 或类似设置,您通常希望将本地分支推送到不同的远程分支。在这种情况下,通用推送规则(由 mozart27 提到)将不起作用,因为它总是将您的本地分支推送到相应的远程分支。
Example: I have a local branch "feature123" which is ready for review (i.e. Gerrit). Our integration branch is "origin/develop". If I use the generic push rule then "feature123" will be pushed for review on "origin/feature123", but what I really want is to push it for review on "origin/develop".
示例:我有一个本地分支“feature123”,可以进行(即 Gerrit)。我们的集成分支是“origin/develop”。如果我使用通用推送规则,那么“feature123”将被推送到“origin/feature123”上进行审核,但我真正想要的是推送到“origin/develop”上进行审核。
Solution: In SourceTree you can create a Custom Action:
解决方案:在 SourceTree 中,您可以创建自定义操作:
Menu caption: Push for review
Script to run: cmd
Parameters: /c git push origin $SHA:refs/for/develop
Remember to add Git to your path to enable cmd to use it.
请记住将 Git 添加到您的路径以启用 cmd 以使用它。
Then, instead of clicking "Push", you right-click your commit, and select "Custom Actions -> Push for review".
然后,不是单击“推送”,而是右键单击您的提交,然后选择“自定义操作 -> 推送以供审核”。
Ofcourse these 2 solutions can coexist, having the generic push rule ensuring that you always send for review when pushing to a remote branch, and the custom action for when you want to send a feature branch for review on the integration branch.
当然,这 2 个解决方案可以共存,具有通用推送规则,确保在推送到远程分支时始终发送以供,以及在集成分支上发送功能分支以供时的自定义操作。