Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make GIT ignore my changes

Tags:

git

People also ask

How do I get rid of my changes in git?

There are two Git commands a developer must use in order to discard all local changes in Git, remove all uncommited changes and revert their Git working tree back to the state it was in when the last commit took place. The commands to discard all local changes in Git are: git reset –hard. git clean -fxd.

How do I checkout and ignore changes?

you can do git checkout -m <branch-name> to merge conflicts and checkout to the branch and resolve conflicts yourself, or git checkout -f <branch-name> to ignore changes.


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.

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.


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

git reset --hard

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.