Reputation: 6151
I needed to fix a change from a previous release. So I commited my current changes using git -a -m "latest"
and then followed this QA here: How to revert Git repository to a previous commit? to jump back about a month. This worked very well. I made the changes needed. I then performed a
git checkout master
To get back to the present. Unfortunatley I then discovered that when I performed my commit - I'd forgotten to perform a
git add .
As such although any changes I've made were there...any new files did not get committed.
Are these permanently lost or is there a way back?
Upvotes: 0
Views: 47
Reputation: 31284
those files are not lost at all:
when switching to another branch, any uncommitted files will be left untouched. that is: you will find them in your working directory, even if you are in the new branch!
if the switch-to branch already contains files with the same name, git will refuse to switch, and ask you to remove or commit the local files first.
if however, you manually remove those files, then you have just deleted files outside the control of git - which means that the only way to recover those files is outside of git as well (e.g. your local backup)
Upvotes: 2