Gitlab管理之七–执行rebase操作

1. 简介:

当我们长时间的运行在分支上的话,我们有时想要同步master,可以通过合并到master后,再切换到我们所在的分支,Git有一个更好的方式来这个,叫做rebasing。 在rebasing中,相当于把你当前的branch分支合并到master,并同步master状态。不过是一步完成了。

2. 使用终端进入到cookbook项目,并创建一个分支。
mike@win10-001 MINGW64 ~/cookbook/cookbook (master)
$ git checkout -b rebase-branch
Switched to a new branch 'rebase-branch'
3. 创建一个新的文件并提交它。
mike@win10-001 MINGW64 ~/cookbook/cookbook (rebase-branch)
$ echo "File content" >> another_file.md

mike@win10-001 MINGW64 ~/cookbook/cookbook (rebase-branch)
$ git add .
warning: LF will be replaced by CRLF in another_file.md.
The file will have its original line endings in your working directory.

mike@win10-001 MINGW64 ~/cookbook/cookbook (rebase-branch)
$ git commit -m 'Another commit'
[rebase-branch c20f042] Another commit
  1 file changed, 1 insertion(+)
  create mode 100644 another_file.md
4. 切换到master分支。
mike@win10-001 MINGW64 ~/cookbook/cookbook (rebase-branch)
$ git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.
5. 假如先前推送过代码分支到Gitlab服务器,再执行rebase,那么在推送时候,可能服务器会报错。为了克服这个问题,可以使用-f参数。
$ git push origin rebase-branch –f
6. 在master分支上创建提交。
mike@win10-001 MINGW64 ~/cookbook/cookbook (master)
$ echo "1" >> README.md

mike@win10-001 MINGW64 ~/cookbook/cookbook (master)
$ git add .
warning: LF will be replaced by CRLF in README.md.
The file will have its original line endings in your working directory.

mike@win10-001 MINGW64 ~/cookbook/cookbook (master)
$ git commit -m 'Commit in master'
[master acb491e] Commit in master
  1 file changed, 1 insertion(+)
7. 切换到rebase-branch 分支
mike@win10-001 MINGW64 ~/cookbook/cookbook (rebase-branch)
$ git rebase master
First, rewinding head to replay your work on top of it...
Applying: Another commit

你可能感兴趣的:(Gitlab)