0

I have a Git repo where I keep my latest code. Whenever I update the code in this repo, I go to the cloned production working tree and run git pull to get the latest code from the repo.

This morning I tried this, and received a git error stating that my working tree had uncommitted changes (which should never happen because all developers know not to modify this code directly.) I decided not to keep the local production changes, and I did git checkout on the file to get the latest from the repo. This also failed with an error.

I tried several more steps and they all failed. Can anyone please help me figure out how to dump the local file changes and restore the latest file from the repo?

There's one possible complication: I tried git rm on the offending file hoping I could remove it from my working tree and then successfully pull the file from the repo. This also did not work and now the git rm is on the repo HEAD.

Kara
  • 6,115
  • 16
  • 50
  • 57
Chris Barnhill
  • 621
  • 1
  • 7
  • 12
  • reset your branch to a known good commit from upstream. then do a checkout and tell us the exact errors should any occur. – mnagel Jul 22 '13 at 21:48
  • @mnagel I did 'git reset --hard HEAD^1' followed by 'git checkout' No errors reported. Then I tried 'git pull ...' and got the locally modified file error again. – Chris Barnhill Jul 22 '13 at 22:28

1 Answers1

2

If you have local changes, perform

git stash

before git pull. With stash all the changes will be moved aside thereby allowing the pull to succeed. Since, as you described, you don't need the local changes, you can then perform

git stash drop

which will discard the last stash.

You also have this answer.

Community
  • 1
  • 1
GoZoner
  • 67,920
  • 20
  • 95
  • 145