R's Workshop

Git Rebase Onto

Git rebase --onto 指令可把某一段連續的 commits rebase 到新的 parent commit 上. 我通常會用這個方式捨棄當前 branch 和目標 branch 重複但不完全相同的 commits, 避免直接 rebase 時遇到 conflict.

Basic Git Rebase

Rebase a Series of Commits by –onto

Concliusion

Syntax

# Rebase a series of commits
git checkout BRANCH_NAME or REBASE_UNTIL_COMMI
git rebase --onto NEW_PARENT_COMMIT OLD_PARRENT_COMMIT <REBASE_UNTIL_COMMIT>

# Rebase a part of commits of a branch
git checkout BRANCH_NAME
git rebase --onto NEW_PARENT_COMMIT OLD_PARRENT_COMMIT

Reference

Git