Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a pull erase all changes in the working directory?

Tags:

git

New to git (through my new job) and being instructed to "just do a pull before you commit", I did so. Much to my surprise, all changes in my working directory disappeared.

  • How did this happen?
  • Where did these file go?
  • Is there a way to restore them?

Thanks.

like image 552
Very Objective Avatar asked Jan 23 '16 18:01

Very Objective


Video Answer


1 Answers

The command git pull is effectively an alias for git fetch and git merge. Whoever was instructing you probably did a poor job, because git pull right before you commit will indeed wipe out all your work. What they should have told you to do instead was commit, then git pull, or if you don't want a merge history use git pull --rebase instead. After that you can git push.

I don't believe there is any way to get back your un-committed work if it was overwritten by a merge initiated by git pull, unfortunately.

Also as a not-super-related friendly reminder, make sure every time before you start working on a new commit you git pull to get any commits anyone else has been working on.

like image 165
Maximillian Laumeister Avatar answered Sep 30 '22 01:09

Maximillian Laumeister