バージョン管理されたファイルのいくつかの行を変更した場合、コマンドラインで行の変更を元に戻すことはできますか?
ファイル全体に対して次のようにします。
git checkout /path/to/file.extension
しかし、次のようなことをしています
git checkout /path/to/file.extension --line 10
これは可能ですか?
バージョン管理されたファイルのいくつかの行を変更した場合、コマンドラインで行の変更を元に戻すことはできますか?
ファイル全体に対して次のようにします。
git checkout /path/to/file.extension
しかし、次のようなことをしています
git checkout /path/to/file.extension --line 10
これは可能ですか?
を使用git checkout -p
して、各ハンクを個別に表示し、それらをチェックアウトするか、そのままにしておくかを決定できます (さらに絞り込みたい場合は、オプションのパス引数も使用します)。
マットの答えを詳しく説明するにgit checkout --patch -- <path argument>
は、次のオプションを使用してインタラクティブ モードを開始します。
y - stage this hunk
n - do not stage this hunk
q - quit; do not stage this hunk or any of the remaining ones
a - stage this hunk and all later hunks in the file
d - do not stage this hunk or any of the later hunks in the file
g - select a hunk to go to
/ - search for a hunk matching the given regex
j - leave this hunk undecided, see next undecided hunk
J - leave this hunk undecided, see next hunk
k - leave this hunk undecided, see previous undecided hunk
K - leave this hunk undecided, see previous hunk
s - split the current hunk into smaller hunks
e - manually edit the current hunk
? - print help
y
n
s
およびe
オプションは、開始するのに適した場所です。
以下も参照してください。
--patch