How can one discard modifications from tracked files similarly to what git add -p does with the index? That is I have modified a tracked file and want to undo only parts of the file?
One can use
git checkout -p
to undo parts of a tracked file (see git checkout):
you can use
git checkout -pto selectively discard edits from your current working tree.
Example Output
$ git checkout -p
diff --git a/foo.txt b/foo.txt
index 98d8da3..dfd6895 100644
--- a/foo.txt
+++ b/foo.txt
@@ -1 +1 @@
-Hello world
+Hello world!
Discard this hunk from worktree [y,n,q,a,d,/,e,?]?
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