2011-08-05 17 views
55

Jeśli zmodyfikowałem kilka linii wersjonowanego pliku, czy możliwe jest cofnięcie zmian linii linii za pomocą wiersza polecenia?Czy można git-checkout pojedynczej linii zamiast całego pliku?

Podobnie jak zrobiłbym dla całego pliku z:

git checkout /path/to/file.extension 

ale robi coś takiego, powiedzmy

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

jest to możliwe?

Odpowiedz

85

Możesz użyć git checkout -p, aby zobaczyć każdy przystojniak indywidualnie i zdecydować, czy je sprawdzić, czy pozostawić tak, jak jest (i który bierze opcjonalny argument ścieżki, jeśli chcesz go zawęzić dalej).

24

Aby rozwinąć na odpowiedź Matta, git checkout --patch -- <path argument> uruchamia tryb interaktywny z następujących opcji:

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 

The yns i e opcje są dobrym miejscem, aby rozpocząć.

Zobacz także:

Powiązane problemy