git rebase命令行

  1. 更新到最新的base分支
$ git checkout <base-branch>
$ git pull <base-branch>
  1. 更新到最新的工作分支
$ git checkout <work-branch>
$ git pull <work-branch>
  1. 执行rebase操作
    期间可能需要解决冲突,或者放弃rebase操作。
$ git rebase <base-branch>
# resolve conflict
$ git add/rm <file>
$ git rebase --continue/--abort
  1. 提交回远程代码库
$ git push --force-with-lease
  • --force-with-lease
    因为所有本地的commits的hash值都被重写了,所以必须使用--force参数。
    使用"--force-with-lease"来代替"--force"可以更安全的提交代码。源文解释是:it ensures you're not accidentally overwriting other people's changes. It checks if someone else has pushed changes to the branch you're trying to push to.

不过如果只有你一个人在这个分支上工作,用--force也是可以的。

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容