I changed some files but don't use git add
or git commit
, it's just stay in working copy.
Then I use git reset --hard
to force HEAD pointer to one previous commit. Currently, the files I changed before were discarded. So, my confusion is: Is there anyway to get the changes back?
Asked
Active
Viewed 146 times
-1

Justin M. Ucar
- 853
- 9
- 17

Allen
- 6,745
- 5
- 41
- 59
-
Next time use `git stash`: http://git-scm.com/book/en/v1/Git-Tools-Stashing – Jeremiah Winsley Dec 17 '14 at 15:18
-
I'm afraid you threw away all your uncommitted changes – dreyescat Dec 17 '14 at 15:20
-
Did you happen to back up your system between the time you made the changes and when you ran `git reset --hard`. If not, and if you never copied the changed files somewhere else, then the answer is "No". – twalberg Dec 17 '14 at 15:52
2 Answers
1
Its not possible to get back uncommitted changes. Your best bet would be to try cached copies from editor or IDE.

nitishagar
- 9,038
- 3
- 28
- 40
0
As you used git reset --hard
, both your index and working copy were reset.
git reset
default behavior without an option is to keep your changes but as you explicitly asked git to reset the hard way, your changes were deleted. As far as I know there is now way to undo that.
edit : I did not try it, but using git reflog
you may be able to see your changes before the reset. If you do, you can navigate through refs using git reset HEAD@{ref_number}
e.g. git reset HEAD@{1}
.