git命令做什么&#34; hexo init <folder>&#34;到底怎么办?

时间:2016-07-14 03:06:35

标签: git hexo

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


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

但是当我执行命令&#34; hexo init&#34;时,我发现它实际上执行了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'
  ....

所以我想知道git命令做什么&#34; hexo init&#34;执行?

2 个答案:

答案 0 :(得分: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)和模块(.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'
});

答案 1 :(得分:0)

hexo init在这里为您提供博客的主要结构。如果git命令可用,则执行hexo-starter存储库的git clone,否则,hexo-cli会复制包含submodule - assets @ 221419b源的hexo-starter