Gitlab 简明教程

GitLab - Rebase Operation

Description

重新调整基础是让 master 合并到您的分支的一种方法,当您使用长期运行的分支时。

Rebase is a way of merging master to your branch when you are working with long running branch.

Steps for Rebase Operation

Step 1 − 进入您的项目目录并使用 git checkout 命令创建一个名为 rebase-example 的新分支 −

Step 1 − Go to your project directory and create a new branch with the name rebase-example by using the git checkout command −

rebase operation 1

标志 -b 表示新分支名称。

The flag -b indicates new branch name.

Step 2 - 然后创建一个新文件,并在该文件中添加如下内容:

Step 2 − Now, create a new file and add some content to that file as shown below −

rebase operation 2

内容“欢迎来到 Tutorialspoint”将添加到 rebase_file.md 文件中。

The content 'Welcome to Tutorialspoint' will be added to the rebase_file.md file.

Step 3 - 将新文件添加到工作目录,并使用如下所示的消息(通过使用 git commit 命令)将更改存储到存储库中:

Step 3 − Add the new file to working directory and store the changes to the repository along with the message (by using the git commit command) as shown below −

rebase operation 3

标志 -m 用于在提交中添加消息。

The flag -m is used for adding a message on the commit.

Step 4 - 然后切换到“master”分支。你可以使用 git checkout 命令获取远程分支(master 是一个分支名称):

Step 4 − Now, switch to the 'master' branch. You can fetch the remote branch(master is a branch name) by using the git checkout command −

rebase operation 4

Step 5 - 接下来,创建一个另一个新文件,在该文件中添加一些内容并在 master 分支中提交它。

Step 5 − Next, create an another new file, add some content to that file and commit it in the master branch.

rebase operation 5

Step 6 - 切换到 rebase-branch 以获得 master 分支的提交。

Step 6 − Switch to the rebase-branch to have the commit of master branch.

rebase operation 6

Step 7 - 然后,你可以使用 git rebase 命令将 master 分支的提交合并到 rebase-branch:

Step 7 − Now, you can combine the commit of master branch to rebase-branch by using the git rebase command −

rebase operation 7