55
如果我修改了幾行版本化文件,是否可以通過命令行取消行的更改?是否可以對一行代碼進行git-checkout而不是整個文件?
就像我會用整個文件做:
git checkout /path/to/file.extension
但是做這樣的事情,說
git checkout /path/to/file.extension --line 10
這可能嗎?
如果我修改了幾行版本化文件,是否可以通過命令行取消行的更改?是否可以對一行代碼進行git-checkout而不是整個文件?
就像我會用整個文件做:
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
選項是一個良好的開端。
參見: