1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Gitコマンド ブランチ関係(branch, checkout, switch, restore)

Posted at

$ git branch

$ git branch -a

リモートリポジトリにあるブランチを含む全てのブランチの一覧を表示する。

$ git branch <branchname>

<branchname>ブランチを作成する。ブランチの切り替えは行わない。

$ git checkout

「ブランチの切り替え作業」と「作業ツリーのファイルの復元」の2つの役割がある

$ git checkout <branchname>

<branchname>ブランチへ切り替え

$ git checkout -b <branchname>

<branchname>ブランチを作成し、同時に切り替えも行う

$ git checkout -f <branchname>

ファイルや作業ツリーの変更内容を破棄して、強制的に<branchname>ブランチに切り替える

$ git checkout <filename>

ローカルの<filename>の変更内容を取り消す

$ git checkout .

ローカルのすべての変更を取り消す(新規作成されたファイルは残る)

Gitの新コマンド "switch","restore"

Git 2.23から新コマンドswitch,restoreが追加された

$ git switch

$ git switch -c <branchname>

git checkout -b <branchname>と同義
-cはcreateの略

$ git switch <branchname>

git checkout <branchname>と同義

$ git restore

$ git restore .

git checkout .と同義

$ git restore <filename>

git checkout <filename>と同義

参考

git branch コマンド
【Git】あなたが知らない新コマンドswitch/restoreの世界にご招待

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?