2

How can I revert/delete all my changes that I did manually on local.

Example I have 2 branches

1) master branch
2) branch2

I checked out branch 2 and started to do some changes locally. I accidentally replaced a word for all the files. So now all my files are unsynced.

I want to start fresh again. (What ever I have in branch 2 that was committed and pushed) and remove all my local changes.

I've tried

git pull branch2
git reset --hard
git --hard branch2
git checkout .

But my recent changes are still existing in my local. Is there a command to revert this or do I have to clone the branch and start from there?

PS all my local changes were not committed at all.

Thank you

JayC
  • 2,144
  • 8
  • 42
  • 77
  • Possible duplicate of [How to revert Git repository to a previous commit?](https://stackoverflow.com/questions/4114095/how-to-revert-git-repository-to-a-previous-commit) – phd Mar 13 '18 at 10:02

2 Answers2

3

You could do a git stash to temporarily store the changes you made and don't want to commit. And then do a git stash pop later to get them back. If you never want to see those changes ever again, then you can overwrite your local changes with a

git reset --hard

git pull

You said you didn't commit files so there are probably untracked local files that need to be removed. I would run a git clean -f . That'll remove the untracked files. If you also need to remove untracked directories (folders) you can do a git clean -df

Hope that helps!

kimcodes
  • 736
  • 1
  • 6
  • 16
1

This will vanish all the changes done on local and pull down the last committed changes on your branch.

git reset .
git checkout .
git checkout branch2
git fetch && git reset --hard origin/branch2
Pankaj Gadge
  • 2,748
  • 3
  • 18
  • 25