目次
Gitのcheckoutとswitchとrestoreの違いのまとめ
checkoutは、役割が多くわかりづらかったため、git switchとgit restoreの2つに分割されました。
| コマンド | 目的 |
|---|---|
| git checkout | ブランチを切り替え ブランチを新規作成 ファイルを復元 ステージから戻す |
| git switch | ブランチを切り替え ブランチを新規作成 |
| git restore | ファイルを復元 ステージから戻す |
比較表
| 目的 | 従来のコマンド | 現在の推奨コマンド |
|---|---|---|
| ブランチを切り替え | git checkout <branch> | git switch <branch> |
| ブランチを新規作成 | git checkout -b <branch> | git switch -c <branch> |
| ファイルを復元 | git checkout -- <file> | git restore <file> |
| ステージから戻す | git checkout --staged <file> | git restore --staged <file> |
git checkout自体は現在も使えますが、より意図が明確なswitchとrestoreの使用が推奨されています。
Git 公式マニュアル(英語)
https://git-scm.com/docs/git-checkout
関連の記事
