Generally i use Netbeans
IDE
for programming and it has Rich features for helping developer,
so it has feature named History
which stores every changes of that file whenever you save the file it saves it as history.
And it also saves all the commits of git, so it stores all the history from the day you have added project to netbeans to till now,
And additionally you can also compare your historical version of file to current version of file, it is very useful feature.
You can see in below image there is two option under opened file
1.Source(in it you can see and edit current file here)
2.History (in which you can check all the older version of file.)

You can see i have Books.php
file under it in history
tab, there is list of all the older version here from git commit, you can check all of it and also compare it to current file.
So if you have mistakenly done git checkout
then you can check that file's history and you can undo the changes or get back your lost changes.