98

バージョン管理されたファイルのいくつかの行を変更した場合、コマンドラインで行の変更を元に戻すことはできますか?

ファイル全体に対して次のようにします。

git checkout /path/to/file.extension

しかし、次のようなことをしています

git checkout /path/to/file.extension --line 10

これは可能ですか?

4

2 に答える 2

140

を使用git checkout -pして、各ハンクを個別に表示し、それらをチェックアウトするか、そのままにしておくかを決定できます (さらに絞り込みたい場合は、オプションのパス引数も使用します)。

于 2011-08-05T22:12:30.083 に答える
51

マットの答えを詳しく説明するに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オプションは、開始するのに適した場所です。

以下も参照してください。

于 2016-08-26T04:47:37.087 に答える