Git recover uncommitted changes
Asked Answered
S

6

14

I had a lot of local changes.

I just accidentally did

git merge another_branch
git reset --hard HEAD^

on a lot of work. :( with the intention I didn't want the merged changes in here.

How do I recover the original state?

No, the local changes were never committed/stashed.

No way?

Selfexcited answered 13/7, 2010 at 18:56 Comment(2)
Have you looked into git stash? Might be what you need, but I'm not 100% certainDendrology
See also steps to recover staged filesDollop
M
12

If the changes had never been committed, stashed, or staged, then you're out of luck. If they have, then you should be able to get your changes back by looking for them in git reflog.

Morion answered 13/7, 2010 at 18:59 Comment(0)
H
21

Foy anyone who is facing this problem in IDEs, there is a solution.

Search for the IDE editor history files of your IDE. I had a problem with Android Studio, so here I will give you a solution for Android Studio.

For example: In Android Studio you can always see the previous files by right clicking on the project folder → Local HistoryShow History.

You can see the change history of files and you can also open the files and compare it with new files side by side. If you need the old code, just copy paste it from there.

Hygrometer answered 12/9, 2017 at 10:25 Comment(3)
This was the solution for my problem!!Dulin
Similar to this suggestion, some IDE's automatically save back up files. For example, MATLAB, since 2012 or 2013, automatically saves backup m-files with the .asv extension in the same directory of the original file.Orethaorferd
saved my day (y)Cordite
M
12

If the changes had never been committed, stashed, or staged, then you're out of luck. If they have, then you should be able to get your changes back by looking for them in git reflog.

Morion answered 13/7, 2010 at 18:59 Comment(0)
L
1

Although the uncommitted modifications to tracked files will have been lost, I think any untracked files will still be around unless you subsequently deleted them.

Landsturm answered 14/7, 2010 at 2:56 Comment(0)
K
1

Try undoing on the file directly from the IDE. You'll get what you need.

It is probably not helpful for @Lakshman Prasad, but it will help someone else :-D

Kettering answered 8/1, 2020 at 10:13 Comment(1)
There isn't anyone by the name "Lakshman Prasad" here. What does it refer to?Wire
S
1

Look into the Recycle Bin!

I found my deleted (uncommitted) files there.

Solicitous answered 8/4, 2020 at 19:1 Comment(1)
What system? Windows?Wire
K
0

I was able to recover my files, by using git log -g. My changes were there, because I committed them once, uncommitted my changes and then I saw all files on which I was working were lost.

By doing git log -g || git reflog -g it will display the recent commit logs.

I found my commit hash and I checked it out to that using this command: git reset #commitHashID

This may help someone with a similar scenario.

Kickshaw answered 14/6, 2020 at 17:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.