3

I'm having an issue with git where I can't retrieve changes that were overridden by git pull.

I had started work on a project without a GitHub repository, which I then later made. I forked the repository when it was made, which included a README file.

I added the files, locally, that I wanted to push the the repository using git add, but then realized I should pull the README first from the GitHub repository.

After pulling, I attempted to push my changes, but instead got the message Everything up-to-date.

I used the ls command to find that the files added with git add were removed and replaced by the README.md.

These are the commands I performed:
commands

Using git log just showed the commits made by the other person working on the project on the README. I guess that was expected, considering I had made no commits.

Using git reflog showed that I made one pull, (HEAD@{0}) but using git reset --hard HEAD@{0} didn't seem to do anything. I also attempted git reset --hard HEAD@{"20 minutes ago"} but only got warnings that the log only went back to my first pull.

Is there a way to restore uncommitted changes overwritten by a pull?

EDIT:

I apologize for not doing my homework, I noticed a question on the sidebar that this question is a duplicate of: Git pull deleted uncommitted changes

I'm going to be using the lost-found (cd .git/lost-found/other) to attempt to restore my changes.

Is there an easier way to restore the changes than lost-found, I guess is the new question. If not, I'll answer myself with the method I'm using.

Community
  • 1
  • 1
nasonfish
  • 455
  • 1
  • 4
  • 14

1 Answers1

3

As mentioned in the question, a solution I used to restore my changes was using git's lost-found.

I used cd .git/lost-found/other/ to take myself to the lost and found where the files were.

I opened each file in the directory to see what it's name was, then moved it to the correct directory with the correct name.

I used git add to add the changes and commit them, so now I won't lose them again.

nasonfish
  • 455
  • 1
  • 4
  • 14