git rebase 使用

  1. 从master上拉个分支  命名为myproject;
  2. 本地写代码,写完以后需要提交时:(1) git status   (2) git add .  (3) git commit -m 'xxx'
  3. 切换到master, 更新master    (1) git pull
  4. 切换到我的分支,(1)git checkout myproject,    再(2)git rebase master  
  5. 第四步可能会有冲突,解决冲突后,再 (1) git status   (2)   git add .  (3)  git status
  6. 此时根据提示我们可以继续rebase ,   (1) git rebase --continue
  7. 切到master, 合并我的分支  (1) git checkout master   (2) git merge myproject
  8. 最后提交代码   (1)git push 

  git  cherry-pick

   需要将其他分支的更新添加到当前分支,比如将master上的更改更新到release上去,使用 :(1) git cherry-pick commitId  (遴选)    (2) git status

   有冲突,先解决冲突,再git add .  继续 git cherry-pick --continue (注意git add 后不要git commit)

   没有错误就git push提交代码

   如果中间操作失误,可以用 git rebase --abort 放弃rebase , 从头再来

使用rebase  可以清理提交树,将多个commit分支合为一条

参考:

https://www.jianshu.com/p/08c3f1804b36

https://git-scm.com/book/zh/v2/Git-%E5%88%86%E6%94%AF-%E5%8F%98%E5%9F%BA

原文地址:https://www.cnblogs.com/aloehui/p/9468926.html