bodokaiser
bodokaiser

Reputation: 15752

How to revert working stage to last commit in git?

I have edited some files in working stage (not added them with git add -A. no commitment).

Now I would like to revert the changes back to the last commit in my local branch.

What is to do?

I already searched a bit and found:

git rebase -i HEAD

but then I get:

Cannot rebase: You have unstaged changes.
Please commit or stash them.

So what is the right way?

Upvotes: 0

Views: 3292

Answers (5)

Manjunath Manoharan
Manjunath Manoharan

Reputation: 4617

Just do the command below. It will remove your changes

git reset HEAD .
git checkout .

Upvotes: 0

twid
twid

Reputation: 6686

if you dont want keep those changes then

git reset --hard

or if you want to keep them

git reset --soft

if you want to save so you can use them letter on then

git stash

to apply those latter on

git stash --apply stash@{number}

Upvotes: 1

Jose L Ugia
Jose L Ugia

Reputation: 6260

Now you're into that I'll strongly recommend to give a read to this article, and get it understood forever. http://git-scm.com/2011/07/11/reset.html

Upvotes: 1

pebbo
pebbo

Reputation: 581

With

git stash

you can store your currently working state to the stash and will have access to the files later on. After you "stashed", you should automatically be at your last commit.

Upvotes: 2

Mark Longair
Mark Longair

Reputation: 468191

You can throw away all your uncommitted changes with:

git reset --hard

WARNING: this really will get rid of all your changes that are staged or just in your working tree and go back to the state of the last commit, so use it with care.

If you might want your local changes back again, and just want to get them out of the way temporarily (e.g. to work on something else) you could just do:

git stash

... instead

Upvotes: 3

Related Questions