7

I made some changes on my local machine and I don't want to keep them.

When I perform a pull to get the recent changes from the server I get a message saying that I have unstaged changes and I must commit or stash them.

But I don't want to do it. I want to cancel them. How to do this?

Samurai Jack
  • 2,985
  • 8
  • 35
  • 58
  • Possible duplicate of [git: undo all working dir changes including new files](https://stackoverflow.com/questions/1090309/git-undo-all-working-dir-changes-including-new-files) – phd Jul 31 '17 at 17:40

2 Answers2

15

git checkout . to undo all non-commited changes on tracked files.

git clean -f to remove non-commited files.

PS: . in git checkout . is shell wildcard that means "all files within current directories and subdirectories". You can use any wildcard or path (git checkout path/ or git checkout ./*.py)

Arount
  • 9,853
  • 1
  • 30
  • 43
2
git reset --hard

Will revert your repository to a clean state.

git reset <commit> Will change the index to point at that commit, by default it's HEAD, so your most recent commit.

The --hard flag will also revert any files to what they were at that commit.

SpoonMeiser
  • 19,918
  • 8
  • 50
  • 68