LoginSignup
17
17

More than 5 years have passed since last update.

gitで変更の一部のみコミット対象とする/変更を取り消す

Last updated at Posted at 2012-03-16

ワークツリーに加えた変更のうち一部分だけをaddしたいときには
git add -p
すると,変更部分ごとにaddするかどうかを選択できる.
逆にgit checkout -pで,一部の変更を消す(正確にはaddされていない=unstagedな変更から消す)ことができる.
デバッグプリントのコードを消したいときなどに便利.

どちらもyやnなどで選択した後に毎回enterを押す必要があり面倒だが
git config --global interactive.singlekey true
を実行しておくと,yやnなどを押した時点で決定できる.

# 選択してgit addするかどうか決める
git add -p [file_or_dir]
# addされてない変更それぞれに対してgit checkout
git checkout -p [file_or_dir]
# git add/checkout -p時に,エンターでの決定を省略する
git config --global interactive.singlekey true

17
17
1

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
17
17