Ответ 1
Использовать интерактивную проверку
Следующий синтаксис git-checkout
,
git checkout --patch <tree-ish> -- <paths>
или, что эквивалентно,
git checkout -p <tree-ish> -- <paths>
позволяет вам интерактивно проверять ханки из одного или нескольких файлов, перечисленных в <paths>
, как записано в <tree-ish>
(чаще всего, фиксация).
Подробнее см. git-checkout
man page.
Пример
Чтобы исправить идеи, вот пример игрушек (нерелевантный stdout опущен):
# set things up
$ mkdir test
$ cd test
$ git init
# create some content and commit
$ printf "Hello, world.\n" > README.md
$ printf "foo\nbar\nbaz\n" > test.txt
$ git add .
$ git commit -m "initial commit"
# modify the working tree
$ printf "another line\n" >> README.md
$ printf "foo\nfoo\n" > test.txt
# now restore stuff from test.txt as recorded in master tip
$ git checkout -p master -- test.txt
diff --git b/test.txt a/test.txt
index 0d55bed..86e041d 100644
--- b/test.txt
+++ a/test.txt
@@ -1,2 +1,3 @@
foo
-foo
+bar
+baz
Apply this hunk to index and worktree [y,n,q,a,d,/,e,?]? y
error: patch failed: test.txt:1
error: test.txt: patch does not apply
The selected hunks do not apply to the index!
Apply them to the worktree anyway? y
# Sanity check: inspect the working tree
# (the hunk "bar\nbaz" from test.txt was restored, as desired)
$ cat test.txt
foo
bar
baz
# (README.md, on the other hand, was not affected, as desired)
$ cat README.md
Hello, world.
another line