Squadrons
Squadrons

Reputation: 2557

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

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

Upvotes: 3

Views: 79

Answers (3)

Haozhun
Haozhun

Reputation: 6521

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.

Upvotes: 2

user1756254
user1756254

Reputation: 369

Sorry to say I think you've lost your uncommited work forever :-(

For a better explanation see http://git-scm.com/book/en/Git-Basics-Undoing-Things

Upvotes: 1

j883376
j883376

Reputation: 1125

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.

Upvotes: 3

Related Questions