Consider the following situation:
$ printf $'line1-v1\nline2-v1\n' > test.txt $ git init . $ git add test.txt $ git commit -m 'Initial commit' $ printf $'line1-v2\nline2-v2\n' > test.txt
magit-status looks like this:
Head: master Initial commit Unstaged changes (1) modified test.txt @@ -1,2 +1,2 @@ -line1-v1 -line2-v1 +line1-v2 +line2-v2 Recent commits 285d881 master Initial commit
The task is to stage just the changes in the first line. But if you try doing it the obvious way (stage the removal of
line1-v1 and the addition of
line1-v2), the lines end up in the wrong order in the index:
Head: master Initial commit Unstaged changes (1) modified test.txt @@ -1,2 +1,2 @@ -line2-v1 line1-v2 +line2-v2 Staged changes (1) modified test.txt @@ -1,2 +1,2 @@ -line1-v1 line2-v1 +line1-v2 Recent commits 285d881 master Initial commit
The obvious work-around is to edit the source file and temporarily undo the changes to
line2. But, is there a simpler way, which doesn't involve editing the source file?
If Magit had a way of editing the file's contents in the index, then that would be an option - one could then simply reorder the lines after staging, or just apply the edit there directly. But there is no way to do this, as far as I can tel.