git rebase
git
書き方
git rebase [-i] [--onto <base>] <upstream>自分のコミットを別の土台の上に付け替えます。ハッシュが変わるので、他の人がすでに取得したブランチにはrebaseせずmergeを使います。
よく使うオプション
| オプション | 意味 |
|---|---|
| -i | interactive: reorder, squash, reword, drop commits |
| --onto <base> | move the range onto a different base |
| --continue | carry on after fixing a conflict |
| --abort | put the branch back exactly as it was |
| --skip | drop the commit that will not apply |
| --autostash | stash uncommitted work and put it back afterwards |
| --autosquash | apply fixup!/squash! commits automatically |
例
git rebase mainreplays your commits on top of main, giving them new hashes
git rebase -i HEAD~3squash or reword the last three commits
git rebase --abortcancel a rebase and return to the original branch
取り消しに何通りもあるのが混乱のもとです — ブランチの指す先を動かすのと、打ち消すコミットを積むのは別です。
読み方
- 角括弧 [ ] は省いてよい部分です。
- 三点 … は複数並べられるという意味です。
- オプションは大文字小文字を区別します — -r と -R が別物のコマンドもあります。
よくある質問
Q. git rebase は何をしますか。
自分のコミットを別の土台の上に付け替えます。ハッシュが変わるので、他の人がすでに取得したブランチにはrebaseせずmergeを使います。
Q. どう打ちますか。
git rebase [-i] [--onto <base>] <upstream> — 角括弧は省いてよい部分です。
Q. よく使うオプションはいくつですか。
ここにまとめたのは7個です。全部は man git にあります。このコマンドはgitの仲間です。
関連するコマンド
man ページ: man git-rebase