Is it possible to exchange the index state of a certain file with its working tree content?
You can get content from index to anywhere you wish using git showobject-name, where object-name is the SHA1 or :filename (that means the version from index) or revision:filename (that means the version from given revision). So either:
git show :filename > filename.tmp
git add filename
mv filename.tmp filename
or
OBJECT=$(git rev-parse :filename)
git add filename
git show $OBJECT > filename
The former saves the data to disk before modifying the index while the later simply asks the index for object name it had, changes it and than gets the object from object store. At that time, nothing refers to the object any more, but it will not be removed until you run git gc.
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