I have a git repository for one of my websites, originally started with another static site generator. But I thought I'd try out Hexo.
Maybe it would have been cleaner to start from an empty directory, but I started a new branch in my repository and felt safe enough working from there. So I ran hexo init . in the root of the repository. This deleted the .git/ folder, and now all my local data on the repository history is gone. I had not pushed all the commits just before I started this, so I have lost a few days' work.
Perhaps if Hexo detects that it's not being run in an empty directory, it should print a warning _and then exit_ instead of wiping the existing git history.
Sorry about the incident.
@tommy351 I think we need to add check and prompt for confirmation in
https://github.com/hexojs/hexo-cli/blob/master/lib/console/init.js
Maybe you could initialize Hexo in a temporary directory and then, when all files are ready, just copy/move them to target directory? That way there would be no need to touch .git folder at all.
@krzysztof-sikorski Good suggestion, sindresorhus/os-tmpdir may be useful
https://github.com/hexojs/hexo/issues/1740 is the same but in deploy.
terrible bug!
This happened to me too. I was fortunate enough to have a remote backup, but still lost a few days' work. :-(
Is Hexo compatible with git? Does the site/hexo need to be in a sub-directory, or will .git be safe if I initialize Hexo in a temp sub-directory and then just copy/move Hexo files to the main directory?
It is intended for Hexo to be init-ed in an empty directory, see https://github.com/hexojs/hexo-cli/issues/12.
hexojs/hexo-cli#12 is about a non-global Hexo install, and doesn't mention init-ing in empty directories, unless I'm misunderstanding something.
The documentation doesn't state Hexo should be init-ed in an empty directory. This should be mentioned in the setup instructions, and as @terrycloth suggested, if Hexo detects that it's being run in a non-empty directory, Hexo should print a warning and _then exit instead of wiping the existing git history_.
The init command is provided by hexo-cli/lib/console/init.js.
hexo has dependency on hexo-cli.
This issue is fixed with https://github.com/hexojs/hexo-cli/pull/14, pending merge.
@tommy351 please check the PR.
Why this bug still not fixed?
My .git folder was deleted as too.
Why is this not fixed after one year?
What is correct way to resolve this issue? I would like to have my blog in git on different computers. How can i do that and avoid this bug?
I wish to express my significant annoyance that this bug is not fixed yet.... Luckily just happened to a simple/small project with a good remote already.
+1
@lukaMis the right way is to hexo init a new folder and copy your posts/config to it.
PR is created but I do not have to right to merge.
closed via hexojs/hexo-cli#14
@leesei Yeah, closed.
This just happened to me. Please consider re-opening; believed not fixed.
@StoneCypher Although the PR has merged, the npm package hasn't updated yet.
You could modify the package.json file to get the latest change from Github repo.
"hexo-cli": "hexojs/hexo-cli"
Ah, gotcha.
Most helpful comment
My .git folder was deleted as too.
Why is this not fixed after one year?
What is correct way to resolve this issue? I would like to have my blog in git on different computers. How can i do that and avoid this bug?