Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git pull deleted uncommitted changes

Tags:

git

I just made a new repository on github. Starting with a folder full of files, the steps I did were:

git init
git add -A
git remote add origin ...

#Now pull in the first commit that github made
git pull origin master

#Check everything is OK
ls

Eek! All my files have disappeared! What happened? Can I get them back?

like image 667
Eric Avatar asked Apr 22 '12 14:04

Eric


People also ask

Can I recover uncommitted changes git?

The "restore" command helps to unstage or even discard uncommitted local changes. On the one hand, the command can be used to undo the effects of git add and unstage changes you have previously added to the Staging Area.

Will git pull erase my changes?

Never pull before you commit any valid changes. This will wipe off all your changes. To retain your code, you have to commit, then pull, then finally push.

How do I recover a discarded change in git?

Press Ctrl+z for Undo & CTRL+S for saving the changes. It's worked for me.


1 Answers

For me the following worked:

  1. Go to the affected file.
  2. Right click and choose Local History and select Show History. From there you can see the history of changes made to the file, and then choose the time you want to bring back the file to.
  3. You will get two windows with the left one having >>. Click on all the >> and this will send your changes to the right window.
  4. Close the window and here you go with your file restored to where you wanted it to be.

I hope it helped!

like image 184
user3518317 Avatar answered Oct 01 '22 20:10

user3518317