← 返回命令列表

Linux command

git-rebase 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Rebase onto branch

git rebase [branch]

Interactive rebase

git rebase -i [commit]

Rebase last N commits

git rebase -i HEAD~[n]

Continue after conflict

git rebase --continue

Abort rebase

git rebase --abort

Skip current commit

git rebase --skip

Rebase onto specific base

git rebase --onto [newbase] [oldbase] [branch]

说明

git rebase reapplies commits on top of another base tip, producing a linear project history. It finds the common ancestor of the current branch and the upstream, then replays each commit from the current branch onto the upstream tip. Interactive mode (`-i`) allows reordering, squashing, editing, or dropping commits during the replay, making it a powerful tool for cleaning up commit history. The `--onto` option enables advanced workflows like moving a branch to an entirely new base. Autosquash automatically applies fixup! and squash! commits, supporting the iterative fixup workflow.

参数

-i, --interactive
Interactive mode.
--onto _newbase_
Rebase onto different base.
--continue
Continue after resolving.
--abort
Cancel rebase.
--skip
Skip current patch.
--autosquash
Auto-apply fixup/squash.
--autostash
Auto-stash changes.
-x _cmd_
Run command after each commit.
-p, --preserve-merges
Preserve merge commits.

FAQ

What is the git-rebase command used for?

git rebase reapplies commits on top of another base tip, producing a linear project history. It finds the common ancestor of the current branch and the upstream, then replays each commit from the current branch onto the upstream tip. Interactive mode (`-i`) allows reordering, squashing, editing, or dropping commits during the replay, making it a powerful tool for cleaning up commit history. The `--onto` option enables advanced workflows like moving a branch to an entirely new base. Autosquash automatically applies fixup! and squash! commits, supporting the iterative fixup workflow.

How do I run a basic git-rebase example?

Run `git rebase [branch]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -i, --interactive do in git-rebase?

Interactive mode.