【问题标题】:git staging patches: with hunk smaller than a linegit staging 补丁:大块小于一条线
【发布时间】:2015-07-05 13:38:32
【问题描述】:

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

的输出
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" (# EDITING PATCHES)

【问题讨论】:

    标签: git patch staging


    【解决方案1】:

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

    不过,可能不值得逐字逐句地执行此操作 - 您最终会得到许多没有真正独立相关性的提交。

    【讨论】:

    • 即使 hunks 被限制在一行,有一个类似于 --word-diff=porcelain 的输出会很好。对于工作流程:文字绝对不值得提交,但充其量只是一个藏匿处。到时候,作为工作流程,我会注意逐句逐句,以免一行大块。
    猜你喜欢
    • 1970-01-01
    • 2015-05-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-05
    • 2014-05-10
    • 2011-06-13
    • 2020-10-22
    相关资源
    最近更新 更多