tags:

views:

94

answers:

4

I read that Git mainly add informations about the repository's history, trying to remember every change made, but that there are also commands that make irreversible changes.

What are the commands that I should really pay attention to and avoid to use wrongly because there is not turning back?

+1  A: 

git reset --hard cannot be undone

John Nolan
true, when not commited
Lauri
+3  A: 

According to http://blog.reverberate.org/2009/07/30/gits-needs-a-new-interface/

 $ git checkout foo.c

... will overwrite any local modifications you may have to foo.c without asking.

The MYYN
+1  A: 

You can lose uncommitted changes by using the git reset command. If your changes are committed, you are protected by the reflog for a number of days before it gets cleaned up by gc.

For example, if you checkout, rebase, reset, or merge which all introduce changes, you can go back to a previous commit by running the reflog command and using reset to reset your HEAD to an old commit.

Brian Riehman
+2  A: 

There are two kinds of "destructive" here -- commands that are destructive to your git history and commands that discard changes in your working copy.

Commands that discard work tree changes:

  1. git reset
  2. git checkout

As others have mentioned, the combination of the reflog and the fact that git objects don't immediately get discarded (unless you turn on automatic cleanup) means that you can usually undo operations like git reset/rebase/merge.

These commands, though, actually discard git objects, eliminating the ability to undo:

  1. git gc (by default, this prunes unreachable objects that are at least 2 weeks old)
MikeSep