Kutay Demireren
Kutay Demireren

Reputation: 650

git pull Deleted My Files with Remote

We are 2 people working on the same project. My friend told me that he has done his part and pushed it to GitHub. My part has finished today so I wanted to push too.

To accomplish, I wanted to pull first, merge the files locally and then push it back again.

While I was trying to update my local repo with his commit, I used git pull, this resulted with all my work gone, and instead of my files, his files appeared.

I want to recover my files and then correctly update my repo with his files.

It is good mentioning the process: I got a local branch named "entrance" so first, I switched to master, then git merge entrance for the files being merged, which showed something on screen so I thought merge is done. So at last, I used git pull.

Upvotes: 1

Views: 3087

Answers (1)

Nguyen Sy Thanh Son
Nguyen Sy Thanh Son

Reputation: 5376

If i meet that case, I will do the steps below:

  1. At the first, make sure that you commit your code before pulling your friend's code.

  2. Show reflog to check the history by command: git reflog The output should be:

$ git reflog
90abbe3 HEAD@{0}: pull origin master: Fast-forward
3ab3527 HEAD@{1}: commit: q defer all
962e856 HEAD@{2}: commit: getall terms by tax
2d7f20d HEAD@{3}: commit: bug list create
  1. Reset to the previous commit by command: git reset --hard HEAD@{1}

  2. Investigating the reason why my code gone by using some commands git diff, git branch ..

  3. Finally, find the issue and merge the source agian by git merge or git pull

Upvotes: 6

Related Questions