美文网首页
git rebase命令行

git rebase命令行

作者: CodingCode | 来源:发表于2025-01-24 01:21 被阅读0次
  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也是可以的。

相关文章

网友评论

      本文标题:git rebase命令行

      本文链接:https://www.haomeiwen.com/subject/hsjkujtx.html