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
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

爱尚维

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值