bash 通过 gitlab(或 git)合并分支的最快方法?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31710175/
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-18 13:22:46  来源:igfitidea点击:

Fastest way to merge branches via gitlab (or git)?

gitbashmergegitlab

提问by Kyle Anderson

I have a development branch and a production branch. I push changes from my development server to a remote gitlab install. Then I login to gitlab GUI and do a merge request (which is quite time consuming). Then I "git pull origin production" from my production server.

我有一个开发分支和一个生产分支。我将更改从我的开发服务器推送到远程 gitlab 安装。然后我登录到 gitlab GUI 并执行合并请求(这非常耗时)。然后我从我的生产服务器“git pull origin production”。

The merge request step kind of takes a long time to do. Is there a faster way to do this? Could I just make a bash/shell script to merge development into production and pull down the updates with one command? If so what commands is this merge request running?

合并请求步骤需要很长时间才能完成。有没有更快的方法来做到这一点?我可以制作一个 bash/shell 脚本来将开发合并到生产中并使用一个命令拉下更新吗?如果是这样,此合并请求正在运行哪些命令?

I make merge requests a couple times a day. Anything to speed up the process I have would be great.

我每天发出几次合并请求。任何可以加快我的进程的方法都会很棒。

回答by nwinkler

You can merge changes without going through a UI - this is one of the core functionalities of Git. Assuming you have two branches (developmentand production), here's how you would merge changes:

您可以在不通过 UI 的情况下合并更改 - 这是 Git 的核心功能之一。假设您有两个分支(developmentproduction),以下是合并更改的方法:

# Check out development branch
git checkout development

# Make changes, commit...
...

# Optional: Push development changes to the remote
git push origin development

# Check out production branch
git checkout production

# Merge the changes from the development branch
git merge development

# Push the changes to the remote
git push origin production

# Check out the development branch again
git checkout development

Now log into the production server and pull the changes there.

现在登录到生产服务器并将更改拉到那里。

You could of course put the above checkout/merge/push steps into a script - that's quite common to do.

您当然可以将上述结帐/合并/推送步骤放入脚本中 - 这很常见。

There are ways to automatically pull changes when something changes. Here are a couple of links for you:

有一些方法可以在发生变化时自动拉动变化。这里有几个链接供您参考: