3
votes

I have this file committed:

foo.txt

line 1
line 2
line 3

Now I modify it to become:

line 1
line 1.5
line 2
line 2.5
line 3

and I run git add . && git diff --cached foo.txt and this is what I get:

diff --git a/foo.txt b/foo.txt
index c4dfc64..4942553 100644
--- a/foo.txt
+++ b/foo.txt
@@ -1,3 +1,5 @@
 line 1
+line 1.5^M
 line 2
+line 2.5^M
 line 3

Let's say I now want to remove line 1.5 from the index and keep line 2.5, how would I do this with LibGit2Sharp?

This can be also asked the other way around: how do I add parts of the file to index? I'm looking for some kind of programmatic version of git add -p.

1

1 Answers

1
votes

There is obviously no easy (understand : LibGit2Sharp-native) way to do this.

But it may be possible. Why do you want to remove this particular line ? It depends on your criteria, but the simpler way is to simply edit the file itself (helped by the result of git diff --cached foo.txt). So git will not stage your unwanted modifications.