Git自学成才——rebase完整版
2016-08-16 本文已影响265人
wIsper
我在自己的开发分支上,而master分支上面有很多提交,现在需要我把master上面的更改rebase到自己的分支。
查看分支
$ git branch
* dbg_lichen_comment
master
我现在在自己的分支上,切换分支
$ git checkout master
再次查看分支
$ git branch
dbg_lichen_comment
* master
拉取master上面的最新代码
$ git pull --rebase
再切换回自己的分支
$ git checkout dbg_lichen_comment
执行rebase变基
$ git rebase master
...
Auto-merging app/build.gradle
CONFLICT (content): Merge conflict in app/build.gradle
...
When you have resolved this problem, run "git rebase --continue".
If you prefer to skip this patch, run "git rebase --skip" instead.
To check out the original branch and stop rebasing, run "git rebase --abort".
出现了冲突,如提示的一样,--continue表示继续;--skip表示跳过;--abort表示中断。
解决了冲突之后,尝试--continue
$ git rebase --continue
app/build.gradle: needs merge
You must edit all merge conflicts and then
mark them as resolved using git add
就像提示说的一样,需要add表示已经解决冲突。
此时我查询一下当前状态
$ git status
rebase in progress; onto 726ee8d
You are currently rebasing branch 'dbg_lichen_comment' on '726ee8d'.
(fix conflicts and then run "git rebase --continue")
(use "git rebase --skip" to skip this patch)
(use "git rebase --abort" to check out the original branch)
提示正在rebase的过程中,此时头指针处于游离态。
那么,我add一下已经解决了冲突的文件
$ git add app/build.gradle
之后,我再次尝试continue(如果有多个冲突,则会反复执行上一步操作)
$ git rebase --continue
Applying: 【Sprint6.0】【feature开发】【story=newsAnd-14】abc
Applying: 【Sprint6.0】【feature开发】【story=newsAnd-14】123
此时,已经成功完成了rebase,然后push
$ git push origin :dbg_lichen_comment // 先删除远程分支
$ git push origin dbg_lichen_comment:dbg_lichen_comment // 再push