Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git - checked out a file from a previous commit, did I lose the uncommitted work I had?

Tags:

git

I had changed a file a decent amount, and wanted to see what changed since the last commit. My changes were not commited.

I used git checkout /path/to/file and successfully grabbed the file from my last commit.

Is there any way to go back to the uncommited work I had added, or is that lost forever?

Thanks

like image 438
Squadrons Avatar asked Dec 05 '25 14:12

Squadrons


2 Answers

When you checkout a file, it overwrites the file meaning that it is gone.

In the future, use git diff to see what has changed. Using git diff with no arguments will show all changes from the directory you're in or you can do git diff /path/to/file for the diff of just that file.

like image 72
j883376 Avatar answered Dec 08 '25 04:12

j883376


Unfortunately, yes, you have probably lost it forever.

You'll have to write that code again.

Next time, when you want to do something like this, you may use git stash. Type git help stash to see what it does. Or as @Lekensteyn suggested, git show may be even better.

like image 24
Haozhun Avatar answered Dec 08 '25 02:12

Haozhun



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!