|
|
|
|
|
by jlgreco
4597 days ago
|
|
My point is that git-reset --hard can remove data from the working tree filesystem that never hit the DAG in the first place: $ git init
Initialized empty Git repository in /home/john/tmp2/.git/
$ echo "foo" > foo
$ git add foo
$ git commit -m 'init'
[master (root-commit) 84fb5d1] init
...
$ echo "bar" >>foo
$ cat foo
foo
bar
$ git reset --hard HEAD
HEAD is now at 84fb5d1 init
$ git reflog
84fb5d1 HEAD@{0}: commit (initial): init
$ git status
# On branch master
nothing to commit (working directory clean)
|
|
If you git reset --hard and you have a dirty working directory, you can absolutely blow work away. That's one of the main reasons to use git reset --hard, but I agree that it needs to be used with intention.
The easiest way to protect against it is to never use it if you have a dirty working directory, always commit first and then reset --hard after you've committed.