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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 12:48:57  来源:igfitidea点击:

How to checkout merge request locally, and create new local branch?

gitgitlabgit-merge

提问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

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

  2. Checkout to newly created branch

    git checkout BRANCHNAME

    i.e (git checkout file_upload)

  1. 将合并请求拉到新分支

    git fetch origin merge-requests/REQUESTID/head:BRANCHNAME

    IE git fetch origin merge-requests/10/head:file_upload

  2. 结帐到新创建的分支

    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-4will 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/configto have git fetchfetch all merge requests.

.git/configgit fetch获取所有的合并请求。

回答by Penny Liu

There is a Check out branchbutton in GitLab.

GitLab 中有一个Check out branch按钮。

enter image description here

在此处输入图片说明



Then you can copy comments from Step 1. Fetch and check out the branch for this merge request.

然后,您可以复制Step 1. 中的注释。获取并签出此合并请求的分支

git fetch <repo> <branch>
git checkout -b <branch>

enter image description here

在此处输入图片说明