rahman
rahman

Reputation: 4948

How to make GIT ignore my changes

Although the title seems similar to previous questions, I could not find the solution to to my Simple case:

Your local changes to the following files will be overwritten by checkout....please commit or stash...

while I don't want to commit or stash or whatever. I just want to go back home :) what should I do please?

Upvotes: 64

Views: 134608

Answers (5)

JoxieMedina
JoxieMedina

Reputation: 1013

If anyone wants to ignore changes on git but keep them on local you can use :

$ git update-index --assume-unchanged <filepath>

Upvotes: 11

Carlos Campderr&#243;s
Carlos Campderr&#243;s

Reputation: 22972

Using just

git checkout .

will discard any uncommitted changes in the current directory (the dot means current directory).

EDIT in response to @GokulNK:

If you want to keep those changes for future use, you have 2 options:

  • git stash: this will save those changes in a stack. You can apply the changes to your working copy later using git stash pop
  • git diff > changes.patch: This will save those changes to the file changes.patch. If you want to apply them to your working copy you can do so: git apply changes.patch.

Upvotes: 94

steffen
steffen

Reputation: 8958

Apart from the mentioned solutions you can stash the changes

git stash

Checkout your branch

git checkout 'ABCD'

And eventually, when you are sure that you don't need anything from the stashed changes, and have checked twice with gitk or gitg, throw away the stash:

git stash drop

That is my preferred way, as it is safer.

Upvotes: 14

Marcin Koziński
Marcin Koziński

Reputation: 11044

To undo local changes and go back to the state from the commit you can:

git reset --hard

Upvotes: 18

Nicolas Barbey
Nicolas Barbey

Reputation: 6797

If you are sure that you don't want to keep your changes, the following line will do :

git checkout -f 'ABCD'

Option '-f' stands for force.

Upvotes: 49

Related Questions