0
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】git checkoutを使ってみよう

Posted at

はじめに

今回は、git checkoutを使って、ブランチの切り替え、ファイルの変更の取消しを行ってみましょう。

git checkout <ブランチ名>

このコマンドを使うと、記述したブランチに切り替えることができます。
また、新しいブランチを作成して、そのブランチに切り替えるという場合は以下のように-bを入れます。

ターミナル
git checkout -b <新しいブランチ名>

git checkout --<ファイル名>

このコマンドを使うと、ファイルの変更を取り消し、ワークツリーのファイルを元の状態に戻すことができます。
ファイル名以外にも、ディレクトリや.を指定することで、以下のように取り消すことができます。
※新規作成したファイル(まだgit addしていないファイル)は元に戻すことができない点に注意が必要です。

ターミナル
git checkout -- <ファイル名orディレクトリ名>   //該当のファイルorディレクトリの変更を取り消す
git checkout -- .                      //すべてのファイルの変更を取り消す

おわりに

「--」を付けたら変更を取り消すコマンド、「--」を付けなかったらブランチを切り替えるコマンドということをしっかり覚えておきましょう。

0
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
0
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?