git switch
git
書き方
git switch [-c <new>] <branch>ブランチの移動だけを担うgit 2.23の命令です。ファイルの中身を書き戻すことはせず、それはrestoreの役目です。
よく使うオプション
| オプション | 意味 |
|---|---|
| -c <new> | create the branch and switch to it |
| -C <new> | create it, or reset it here if it exists |
| - | go back to the branch you were on before |
| --detach <commit> | check out a commit without a branch |
| --track <remote>/<branch> | follow a remote branch |
| -m | carry uncommitted changes across by merging them |
例
git switch mainmoves to main; refuses if that would clobber your edits
git switch -c feature/apicreates the branch and moves there
git switch -jumps back to the previous branch
取り消しに何通りもあるのが混乱のもとです — ブランチの指す先を動かすのと、打ち消すコミットを積むのは別です。
読み方
- 角括弧 [ ] は省いてよい部分です。
- 三点 … は複数並べられるという意味です。
- オプションは大文字小文字を区別します — -r と -R が別物のコマンドもあります。
よくある質問
Q. git switch は何をしますか。
ブランチの移動だけを担うgit 2.23の命令です。ファイルの中身を書き戻すことはせず、それはrestoreの役目です。
Q. どう打ちますか。
git switch [-c <new>] <branch> — 角括弧は省いてよい部分です。
Q. よく使うオプションはいくつですか。
ここにまとめたのは6個です。全部は man git にあります。このコマンドはgitの仲間です。
関連するコマンド
man ページ: man git-switch