0

I've been struggling to undo some local changes that are not consistent with a repository I'm working on. I can't figure out how to just return the file to a completely synced state so that I can return to working on a project. Any idea what's happening here?

image

I've attempted git reset --hard and a few other commands, but to no avail.

HangarRash
  • 7,314
  • 5
  • 5
  • 32
  • 3
    Sometimes, the simplest solution is to clone the repository from scratch: [xkcd.com/1597](https://xkcd.com/1597/). – YSC Mar 12 '23 at 17:48
  • Seconded what @YSC said. New clone is not the most effective way but surely the simplest. – phd Mar 12 '23 at 17:57
  • My guess is the syntax of your hard reset is incorrect. Try `git reset --hard @{u}` which is just short for `git reset --hard origin/main`. Note this will discard your 5 new commits you made on `main`. I assume you don't wish to save them. Note you could save them off to another branch if you wish. – TTT Mar 12 '23 at 19:59
  • You say you are trying to undo local changes, but the screenshot says there are no local changes. Perhaps what you mean by "local changes" is different than what git means. Will you provide more details about what these "local changes" are? What did yo do with the local copy of the code that you want to undo? – Code-Apprentice Mar 13 '23 at 07:24
  • On the other hand, the screenshot says you have 5 local commits. Are these the "changes" that you want to get rid of. If so, `git reset --hard origin/main` should work fine as previously suggested. On a side note, I recommend you read about branches. These are a great tool that allow you to experiment and easily throw away changes if you decide you don't want to keep them. – Code-Apprentice Mar 13 '23 at 07:28

1 Answers1

0

To undo the local commits, you can use this command:

git reset --hard or git reset --hard HEAD~<no. of commits>.

After you have undone all the changes, you can then sync your fork with origin by: git pull