我在Windows 10上安装了Git Bash,我正在关注这段视频https://youtu.be/MIFQwHlEI9o?t=602在VSCode中使用git时,他使用带-p选项的checkout从提交中挑选片段:
$ git checkout 0903304 index.html -p
diff --git b/index.html a/index.html
index 3ebbb46..d95bb1a 100644
--- b/index.html
+++ a/index.html
@@ -10,6 +10,10 @@
<ul>
<li>Item one</li>
</ul>
+
+ <p>Paragraph one</p>
+ <h1>A title</h1>
+ <div><p>Some text</p></div>
</body>
</html>
No newline at end of file
Apply this hunk to index and worktree [y,n,q,a,d,e,?]
当我输入";e";两个版本都加载了该文件,我的光标会自动放在编辑器中。在进行更改并按CTRL+S保存后,我无法退出。我已经试过q、ESC、CTRL+X、wq、:wq和:X!除了用"关闭"关闭文件外,什么都不起作用;x〃;但后来我得到了:
Your edited hunk does not apply. Edit again (saying "no" discards!) [y/n]? 0 [sig] bash 987! sigpacket::process: Suppressing signal 18 to win32 process (pid 6340)
我终于明白了这一点,我遵循了微软的Git补丁/diff模式指南https://vscode-docs.readthedocs.io/en/latest/editor/versioncontrol/以及这篇stackoverflow文章,用于正确编辑hunk:git-add-interactive";你编辑过的大块头不适用";然后在编辑补丁时使用以下内容:
- 将文件另存为任何其他文件CTRL+S
- CTRL+W,输入