Reputation: 650
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
Reputation: 5376
If i meet that case, I will do the steps below:
At the first, make sure that you commit your code before pulling your friend's code.
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
Reset to the previous commit by command: git reset --hard HEAD@{1}
Investigating the reason why my code gone by using some commands git diff
, git branch
..
Finally, find the issue and merge the source agian by git merge
or git pull
Upvotes: 6