I am working on a git repo and issue a command
$ git add .
to save the current modifications,
after 10 minutes, I accidentally made some bad changes, so I want to revert to last add . status.
I searched but find there are only methods to reset to latest commit.
How could I return to the status of ten minutes ago.
Best Answer
Short answer is : you can't, git only offers ways to return to previous commits (e.g : stuff you commiittted using
git commit
)For future use : you can run
git add . && git commit -m WIP
to "save current modifications"Longer answer is : if getting back the previous version of this file is more important than keeping your mental health, you may dig in the list of dangling blobs
What is a dangling blob ?
some way to hackily check "what blobs were modified recently ?" see some indications in this answer
Heh, I knew I had some kind of script somewhere :
the following script will list the unreachable blobs, which have not yet been packed in an object pack (this is generally the case with recent blobs), and sorts them by creation date (actually : uses the creation date of the file on disk as an estimation of when the blob was created)
Some explanations :