git staging补丁:hunk小于一行

时间:2015-07-05 13:38:32

标签: git patch staging

我希望从一个独特的提交中创建一个交互式补丁。我想使用类似

的输出
git diff --word-diff=porcelain [file]

用于交互式修补。命令

git add --edit

建议只有至少一行的大块?

目标:我有一个文本文件的补丁,我想在" LibreOffice"中进行改变。接受或拒绝变更。

示例:

一行中的文本文件:

echo "Thiis is a sentence with one wrong word. This is a clean sentence. Thhe laast one iss alwaays morre dificult" > text.txt

提交

git add text.txt
git commit -m "one"

修改文件

echo "This is a sentence with one wrong word. This is a clean sentence. The last one is always more difficult" > text.txt

git add -e

应该自动切入3个帅哥

"Thiis" > "This"
"Thhe laast" > "The last"
"iss alwaays morre dificult"> "is always more difficult"

我可以获得

--- a/text.txt
+++ b/text.txt
@@ -1 +1 @@
-Thiis is a sentence with one wrong word. This is a clean sentence. Thhe laast one iss alwaays morre dificult
+This is a sentence with one wrong word. This is a clean sentence. The last one is always more difficult

注意:最好的"without introduc[ing] confusing changes to the index"(#编辑补丁)

1 个答案:

答案 0 :(得分:3)

不,git hunks的标准工具是使用线条(或附近的一组更改的线条)。但是,git所做的就是在三种状态中分别拍摄文件的快照;因此,如果您可以访问更改,则可以轻松重播。首先,执行其中一个更改(然后执行提交),然后重播第二个更改(然后执行提交),依此类推。

这可能不值得在逐字的基础上做到这一点 - 你最终会得到很多提交而没有真正的独立相关性。