I am looking to make an interactive patch from a unique commit. I would like to use an output similar as
git diff --word-diff=porcelain [file]
for an interactive patching. The command
git add --edit
propose only hunk that are as least as one line?
Aim: I have a patch for a text files and I would like to stage the changing like in "LibreOffice" accept or reject changes.
Example:
A text file in one line:
echo "Thiis is a sentence with one wrong word. This is a clean sentence. Thhe laast one iss alwaays morre dificult" > text.txt
to commit
git add text.txt
git commit -m "one"
Modifiying the file
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
should be automatically cut in 3 hunks
"Thiis" > "This"
"Thhe laast" > "The last"
"iss alwaays morre dificult"> "is always more difficult"
I can just obtain
--- 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
Note: at the best "without introduc[ing] confusing changes to the index" (# EDITING PATCHES)
No, the standard tools for git hunks are to use lines (or set of changed lines in the near vicinity). However, all that git is doing is taking a snapshot of the file in each of three states; so you could easily replay that if you have access to your changes. First, do one of the changes (then do a commit), then replay the second change (then do a commit) and so on.
It's probably not worth doing this on a word-by-word basis though - you'll end up with many commits with no real standalone relevance.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With