Search code examples
githubgit-shell

How to recover replaced files in local Git repository after pull request?


Originally on my Github are some outdated styles.css and JavaScript files and others.

I was working on my project last night but didn't push it to Github or back it up. It was just saved in my local repository using a series of local, unpushed commits.

Being a newbie that I am, I did a git pull request master, and all the files in my local repository got replaced with the original styles.css and JavaScript that was in my github.

Is there a way to get those files back?

I did a git reset head@{2} where I believe the state of the repository before the pull request was, and it showed some unstaged files.

In Gitshell my command line has "master [+10 ~19 -42 !]" with the text master being yellow.

At this point, what do I do? Currently I seem to have lost a lot of work.


Solution

  • If you have performed commits often you can pretty much get to any of them.

    Use git reflog first (https://git-scm.com/docs/git-reflog). It will show you all the interim commits you've made. Once you find a relevant one you can do git reset #commit_id.