1

当我使用Hexo [ https://hexo.io/]在 github 上部署静态博客时,首先我执行“hexo init”来初始化 hexo 文件夹以生成如下文件和文件夹:

.
├── _config.yml
├── package.json
├── 脚手架
├── 源
| ├── _drafts
| └── _posts
└── 主题

但是,当我执行命令“hexo init”时,我发现它实际上执行了 git 命令:

  [root@localhost buwei]# hexo init blog
  INFO  Cloning hexo-starter to /home/buwei/blog
  Cloning into '/home/buwei/blog'...
  remote: Counting objects: 53, done.
  remote: Total 53 (delta 0), reused 0 (delta 0), pack-reused 53
  Unpacking objects: 100% (53/53), done.
  Submodule 'themes/landscape' (https://github.com/hexojs/hexo-theme-      landscape.git) registered for path 'themes/landscape'
  ....

所以我想知道“hexo init”执行了哪些git命令?

4

2 回答 2

2

hexojs/hexo-cli/lib/console/init.js#initConsole(),它主要执行git clone

  if (args.clone) {
    promise = spawn('git', ['clone', '--recursive', GIT_REPO_URL, target], {
      stdio: 'inherit'
    });
  } else {
    promise = copyAsset(target);
}

然后它删除 git dir ( .git) 和 modules ( .gitmodules)

  return promise.catch(function() {
    log.warn('git clone failed. Copying data instead');

    return copyAsset(target);
  }).then(function() {
    return Promise.all([
      removeGitDir(target),
      removeGitModules(target)
    ]);
  }).then(function() {
    if (!args.install) return;

    log.info('Install dependencies');

    return spawn('npm', ['install', '--production'], {
      cwd: target,
      stdio: 'inherit'
});
于 2016-07-14T04:57:28.527 回答
0

hexo init这里给大家介绍一下博客的主要结构。如果 git 命令可用,它将执行git clonehexo -starter存储库,否则, hexo-cli 复制其子模块 - assets@221419b,其中包含hexo-starter的源。

于 2016-07-15T08:25:45.037 回答