The question is How do I manipulate (dump and load) Git index as text?:
Is there a pair of Git commands that would allow to
- dump current contents of Git index to stdout as text in some format (one entry per line, including full path to the file);
- read text in the above format from stdin into Git index, fully replacing its current contents?
The answer is https://stackoverflow.com/a/53722759/857932 (emphasis mine):
Using git ls-files --stage and git update-index --index-info can get you all the way there, though it's a bit clumsy in spots: removing a file means setting its mode to zero, and renaming a file amounts to duplicate the line <...>
Now this answer does not fully answer the question: it does not address the "fully replacing its current contents?" part, instead suggesting an inconvenient workaround.
I found a way to improve on the answer to address the missing part, and proposed it as an edit: https://stackoverflow.com/review/suggested-edits/21656371
The edit was rejected:
This edit was intended to address the author of the post and makes no sense as an edit. It should have been written as a comment or an answer.
I do not understand this rejection reason. It clearly addresses the original question and the asker (i. e. me), not the answerer. How should I have achieved my intention?
Should I have posted my improvement as a separate answer instead? It feels wrong: I cannot accept the answerer's answer as-is (because it does not fully answer my question) and I cannot accept my own answer, because this won't give the answerer due credit (it was their idea, after all, and only an improvement that is mine).