红穆笔记

git rebase

將 commits 從一個分支合併到另一個分支上。 常用於跨分支的 commits 合併,在被合併分支的最頭部構建新的 `commit`,表示合併完成

100% 瀏覽器本地處理 0 數據上傳

常用示例

在另一個分支的頭節點合併當前分支

git rebase {{目標分支}}

啓動交互式的合併任務,允許對提交的內容進行重新排序、省略、合併或修改

git rebase {{[-i|--interactive]}} {{目標分支或 commit 的 hash}}

處理完衝突文件後,繼續執行合併任務

git rebase --continue

跳過沖突文件,繼續執行合併任務

git rebase --skip

終止正在執行中的合併任務(例如:對於正處於解決衝突中的任務,將其打斷,恢復到合併前的狀態)

git rebase --abort

將分支的部分 commits 生成新的 `commit`,移動到新分支的頭節點

git rebase --onto {{目標分支}} {{當前分支}}

啓動交互式的合併任務,對最近提交的 5 個 commits 進行重新排序、省略、合併或修改

git rebase {{[-i|--interactive]}} HEAD~5

以當前分支優先的策略,自動處理分支間的衝突,執行合併

git rebase {{[-X|--strategy-option]}} theirs {{分支名稱}}

提示:花括號{{…}}是需要替換的參數(路徑、文件名等);命令只在本機終端執行,本站不保存任何輸入。

英文原文對照

展開英文說明與示例(來源 tldr-pages)

Reapply commits from one branch on top of another branch. Commonly used to "move" an entire branch to another base, creating copies of the commits in the new location. More information

Rebase the current branch on top of another specified branch

git rebase {{new_base_branch}}

Start an interactive rebase, which allows the commits to be reordered, omitted, combined, or modified

git rebase {{[-i|--interactive]}} {{target_base_branch_or_commit_hash}}

Continue a rebase that was interrupted by a merge failure, after editing conflicting files

git rebase --continue

Continue a rebase that was paused due to merge conflicts, by skipping the conflicted commit

git rebase --skip

Abort a rebase in progress (e.g. if it is interrupted by a merge conflict)

git rebase --abort

Move part of the current branch onto a new base, providing the old base to start from

git rebase --onto {{new_base}} {{old_base}}

Reapply the last 5 commits in-place, stopping to allow them to be reordered, omitted, combined, or modified

git rebase {{[-i|--interactive]}} HEAD~5

Auto-resolve any conflicts by favoring the working branch version (`theirs` keyword has reversed meaning in this case)

git rebase {{[-X|--strategy-option]}} theirs {{branch_name}}

命令信息

命令名git rebase
用途將 commits 從一個分支合併到另一個分支上。 常用於跨分支的 commits 合併,在被合併分支的最頭部構建新的 `commit`,表示合併完成
適用平臺通用
示例數量8 條
官方文檔https://git-scm.com/docs/git-rebase
數據來源tldr-pages(CC-BY-4.0)· 社區中文翻譯

常見問題

git rebase 命令是做什麼的?

將 commits 從一個分支合併到另一個分支上。 常用於跨分支的 commits 合併,在被合併分支的最頭部構建新的 `commit`,表示合併完成

git rebase 怎麼用?

頁面按場景列出了8 條常用示例:每條示例先說明用途,再給出可直接複製的完整命令(花括號裏是需要替換的參數)。

git rebase 最常用的操作是什麼?

在另一個分支的頭節點合併當前分支:git rebase {{目標分支}}

命令裏的花括號是什麼意思?

花括號{{…}}表示需要替換成你自己的值,例如路徑、文件名;同名參數方括號(如 [-C|--directory])表示可選寫法。