Reputation: 55
On my project, before pushing to the remote branch I just run the git pull command, and it just deleted all the (new) local files that weren't in the branch. And, I didn't get a backup, if the files are deleted it should be somewhere on my computer, right?
Does anyone has faced with a similar issue?
Thanks.
Upvotes: 1
Views: 4621
Reputation: 12209
Call git reflog
to show a history of your actions in this repo. You should see something like this:
bb3139b... HEAD@{0}: pull : Fast forward
622f05a HEAD@{1}: commit: here i'm committing new local files
Basically you want to find the last commit you made before you lost your files. You want commit 622f05a
, so use this:
git reset 622f
This will "undo" your pull, but you can just git pull
again whenever you want to to get those remote updates back.
Upvotes: 4
Reputation: 2110
Since you have committed your changes in local git, you can get rid of all changes and move to the current/previous commit(which you prefer).
This will reset everything to your current commit (getting rid of all changes, staged or otherwise):
git reset HEAD --hard
This will reset everything to the previous commit (also getting rid of all changes, staged or otherwise):
git reset HEAD^ --hard
the ^ next to HEAD means one commit before HEAD, HEAD being where you are currently. You can go two commits back by using ^^, or three with ^^^. Additionally, you can use a tilde to specify the number of commits: ~3 for three commits back.
git reset HEAD~3 --hard
Also, keep in mind that the --hard option means that these commands will throw away any changes you have that are not stashed.
Upvotes: 2