Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to give up unstaged changes

Tags:

git

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?

like image 318
Samurai Jack Avatar asked Dec 05 '22 13:12

Samurai Jack


2 Answers

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)

like image 191
Arount Avatar answered Dec 17 '22 15:12

Arount


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.

like image 29
SpoonMeiser Avatar answered Dec 17 '22 16:12

SpoonMeiser