LoginSignup
31

More than 5 years have passed since last update.

git checkoutでよくやる操作

Last updated at Posted at 2012-12-01

リモートブランチをチェックアウト+追跡する

git checkout foo # ローカルにfooブランチが無い場合

ローカルにfooブランチがある場合は

git checkout -b new-foo --track origin/foo

など.

特定リビジョンの1ファイルをcheckoutする

git checkout sha1_or_branch_name -- path/to/file.sh

ブランチは切り替えない.-pオプションを付けるとgit add -pのように各hunkを適用するか選択できる.

indexに追加していない変更を消す

既にgit addしたものは残し,カレントディレクトリ以下のaddしていない変更を全部消す.よく使う.

git checkout .

一部のみ取り消すなら-pオプションを付ければよい(gitで変更の一部のみコミット対象とする/変更を取り消す).
addしているものも含めるなら普通にgit reset --hardする.

git chekcout -

他にもgitのブランチ移動はよく使う.

# topic branchで実装を終えた
git checkout master
git merge --no-ff -

みたいな形.

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
31