Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hg update 00 and its git alternative

After creating new "master" repository in mercurial I used to always run

hg update 00

(it would only work with more one 0 ...)

This would remove all (tracked/committed) files and folders from repository folder but not the repository and only leave .hg folder. I've learn this from my colleague in previous job and used it ever since. I like the cleanliness about the folder and used it only for master repository which is not edited directly (only cloned).

What this command actually does and what is its alternative in GIT (if any)?

Thank you.

like image 421
vidriduch Avatar asked Dec 19 '25 03:12

vidriduch


2 Answers

There is a difference between hg and git in the way repositories look like on the server (what you call master repository): for mercurial it is similar to what you will clone on your machine: it has a .hg folder and can also have a working directory with files, which can be considered either useful sometimes or to be avoided.

For git on the other hand, you can have what they call a bare repository, having no working tree or no checked out copy of your files; in fact the git files are directly stored in the root folder of your repository instead of in a .git subfolder.

If this is what you want, preventing from having any files, then simply use:

git init --bare [directory]

like image 51
Christophe Muller Avatar answered Dec 20 '25 17:12

Christophe Muller


You've asked two questions. @christophe-muller has the bigger one answered: "what is the git equivalent?

The other was "What [does] this command actually do?", and the answer to that is: It updates to the null revision. That's the revision before the first commit, which itself is revision zero. That's why hg update 0 doesn't work -- it takes you the first real commit. The null commit before that one has the hash/node-id of 000000000000000000000000, which you 00 matches, and the revision number -1.

The more traditional way to do this would be hg update null though hg update -1 works too.

like image 40
Ry4an Brase Avatar answered Dec 20 '25 18:12

Ry4an Brase