After I remove several lines from a git-versioned file, instead of making a new commit that removes those lines, is there a git command(s) that just strips those lines from the commits that originally introduced them? For example, given this file:
$ echo "Line 1" >> foo
$ echo "Line 2" >> foo
$ git commit -a -m "Add 1, 2"
[master 1005cbb] Add 1, 2
1 file changed, 2 insertions(+)
$ echo "Line 3" >> foo
$ git commit -a -m "Add 3"
[master 5036981] Add 3
1 file changed, 1 insertion(+)
$ echo "Line 4" >> foo
$ echo "Line 5" >> foo
$ git commit -a -m "Add 5, 6"
[master 41ca6ab] Add 5, 6
1 file changed, 2 insertions(+)
$ git blame -s foo
1005cbbb 1) Line 1
1005cbbb 2) Line 2
50369811 3) Line 3
41ca6ab6 4) Line 4
41ca6ab6 5) Line 5
Say I remove lines 2-4:
$ sed -i '/Line [234]/d' foo
$ git diff
diff --git a/foo b/foo
index 572d5d9..e486b1b 100644
--- a/foo
+++ b/foo
@@ -1,5 +1,2 @@
Line 1
-Line 2
-Line 3
-Line 4
Line 5
Now instead of committing that change, I want to run something that just removes those lines from the history entirely, resulting in a new tree where 1005cbb (or whatever the new hash is) just adds "Line 1", 5036981 is empty (or gone), and 41ca6ab adds "Line 5".
Is this possible? The closest thing I can think of is to remove each line separately and git commit --fixup hash-of-the-commit-that-added-that-line before rebasing, but I'm curious if there's a better built-in method before I try to automate doing it that way.