by jlgreco · 13y ago · 0 comments
Of course --hard is not on by default so... there is no issue here with git's default behaviour.
> "Git's model is remarkably simple, and that simplicity is the source of many of its benefits. Every other VCS out there is more complex."
Yup, exactly. The simplicity of git's model is hugely important. It allows me to not only know what git will or will not allow me to do (knowledge that in other systems is acquired by studying the docs for each particular command to see what all the flags do) but also lets me figure out what sort of novel operations are possible if I am willing to write a little code of my own.
Example: Update hook that only allows a push if two or more colleagues of the committer have pushed annotations for that commit already? With little more than my knowledge of git's data model, and what update hooks are in the first place, I know that can be done and I know how I could do it.
Every version control system has a way to overwrite a dirty (modified) work directory, so git is hardly any more dangerous than any other tool.
It also won't help you get back uncommitted files that you destroy with `rm`. No other tool does, either.
There are situations that reflog won't get you back from, but those situations are perfectly logical and appropriate exceptions.
Darcs does: if you "darcs revert" to erase your local unrecorded changes you can actually "darcs unrevert" and get them back later. I guess it's a little like "git stash" but not quite, as you can only have 1 saved state and many darcs operations will nuke the unrevert save (loudly and with prompts, so it won't catch you off guard).
$ 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.
It just seems silly, sorry. And while I know little about hg I suspect it's not even true: hg will never delete a file it doesn't understand? What about the equivalent of git clean (which I use daily -- it's loss would be a minor hardship and definitely not an advantage for mercurial)?
Understand that I am very pro-git. I'm just trying to be precise here.
'unrecoverable in acceptable timescale with acceptable resource' would be accurate.
specifically i found it difficult to undo a merge and found that i was in a team where people had decided to use tools they didn't know enough about to have been using at all.
Which really, at the end of the day, is the real problem with git. It's not that it's inherently more dangerous, it's that the CLI is so inconsistent it can be hard to remember what you're doing, what's safe and unsafe, etc. Sometimes you need to pass "--force" for dangerous stuff, sometimes you capitalize the argument (like force deleting a branch). Sometimes "--hard" indicates that you should do the dangerous version of something. Sometimes there's not even a safety switch.