git 如何在本地签出合并请求,并创建新的本地分支?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/44992512/
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
How to checkout merge request locally, and create new local branch?
提问by Lokinder Singh Chauhan
I have GitLab repository there and I need to test every merge request locally, before merging to the target branch.
我在那里有 GitLab 存储库,在合并到目标分支之前,我需要在本地测试每个合并请求。
How can I pull/fetch merge request as a new branch?
如何将合并请求作为新分支拉/取?
回答by Lokinder Singh Chauhan
Pull merge request to new branch
git fetch origin merge-requests/REQUESTID/head:BRANCHNAME
i.e
git fetch origin merge-requests/10/head:file_upload
Checkout to newly created branch
git checkout BRANCHNAME
i.e (
git checkout file_upload
)
将合并请求拉到新分支
git fetch origin merge-requests/REQUESTID/head:BRANCHNAME
IE
git fetch origin merge-requests/10/head:file_upload
结帐到新创建的分支
git checkout BRANCHNAME
即 (
git checkout file_upload
)
OR with single command
或使用单个命令
git fetch origin merge-requests/REQUESTID/head:BRANCHNAME && git checkout BRANCHNAME
git fetch origin merge-requests/REQUESTID/head:BRANCHNAME && git checkout BRANCHNAME
i.e
git fetch origin merge-requests/18/head:file_upload && git checkout file_upload
IE
git fetch origin merge-requests/18/head:file_upload && git checkout file_upload
回答by Guillaume Husta
This is also documented in GitLab online documentation : https://gitlab.com/help/user/project/merge_requests/index.md#checkout-merge-requests-locally
这也记录在 GitLab 在线文档中:https://gitlab.com/help/user/project/merge_requests/index.md#checkout-merge-requests-locally
They supply this script (git alias) :
他们提供这个脚本(git别名):
[alias]
mr = !sh -c 'git fetch merge-requests//head:mr-- && git checkout mr--' -
Then you can use this command :
然后你可以使用这个命令:
git mr origin 4
git先生起源4
So a new local branch mr-origin-4
will be created.
因此mr-origin-4
将创建一个新的本地分支。
回答by Tobias Kienzler
You can also add the line
您还可以添加行
fetch = +refs/merge-requests/*/head:refs/remotes/origin/merge-requests/*
to your .git/config
to have git fetch
fetch all merge requests.
您.git/config
有git fetch
获取所有的合并请求。