I’m teaching HG to my students, as it is a good playskool DVCS (not powerful as GIT but simple to start working with trivial concepts). I use HG because it seems very difficult to destroy previous entries (with the exception of hg rollback), so you have always a chance to get back on train without destroying important data. But i was recently wondering:
- is it true ?
- does GIT offers the same protection (i read somewhere about
rebaseoption which can be very dangerous)
Both are DVCSs, meaning that you’re supposed to clone the repo and push your changes somewhere when you want a backup copy. If you do this diligently, then it becomes irrelevant which destructive tools are available to you, since backups are cheap and easy to maintain.
Now, be warned that I’m a 100% biased Git bigot.
Out of the box, Mercurial only ships with one destructive command, rollback. Everything else is relegated to extensions which must be manually enabled — strip, rebase, etc. These extensions are most certainly destructive in that they rewrite history in-place, or they destroy it. To avoid using these, most Mercurial users prefer to use the Mercurial Queues extension, which lets you maintain changesets as flexible patches before setting them in stone as commits. This essentially amounts to an entire VCS which sits on top of Mercurial. It gets the job done, but it must be consciously applied before the commits are written.
By contrast, Git ships with several commands that may be considered “destructive”, but with one crucial difference — nothing inside Git’s database is ever rewritten. Whenever you use the rebase, filter-branch, or reset commands, new objects are created in the database, and then the branch pointer is updated to point to these. Every time a branch pointer is updated, an entry is appended to its reflog, a history log which sits on top of Git and protects your branch pointers from unwanted updates; it’s always possible to revert a “destructive” command. It can be difficult, in fact, to permanently remove an object from Git’s database — it involves dropping the reflog entry and then pruning the unref’d objects.
In short:
For your use case of teaching, these differences are generally irrelevant anyway — you’ll be teaching the basic commands, and if someone wants to explore, the only way they’ll learn is by chainsawing their arm off. It is said that Mercurial is easier for beginners to learn, but I feel that that’s mostly because it doesn’t expose the index and so is more like Subversion. Complete neophytes to version control might not benefit from this similarity.