在使用hexo-deployer-git时 push 到分支内的都是 hexo 生成的 public 文件夹内容,想要同时把项目变更一起 push 这样就不需要再手动 commit 了~

deploy

deploy:
  - type: git
    branch: master
    repo: <git repo url>

hexo-deployer-git

分析下该插件是如何只将 public 文件夹内容 push 到分支的

hexo-deployer-git/lib/deployer.js

  function setup() {
    const userName = args.name || args.user || args.userName || '';
    const userEmail = args.email || args.userEmail || '';

    // Create a placeholder for the first commit
    return fs.writeFile(pathFn.join(deployDir, 'placeholder'), '').then(() => {
      return git('init');
    }).then(() => {
      return userName && git('config', 'user.name', userName);
    }).then(() => {
      return userEmail && git('config', 'user.email', userEmail);
    }).then(() => {
      return git('add', '-A');
    }).then(() => {
      return git('commit', '-m', 'First commit');
    });
  }
// ......
    fs.exists(deployDir).then(exist => {
      if (exist) return;
    
      log.info('Setting up Git deployment...');
      return setup();
    })

该段可以看出每次提交时判断.deploy_git 文件夹是否存在,不存在会创建 .deploy_git并同时 git init把该文件夹当作新的提交域,
所以删除了 .git git add -A 就能 add 全部变更文件了

// ........
fs.exists(deployDir).then(exist => {
  if (exist) return;

  log.info('Setting up Git deployment...');
  return setup();
})
.then(() => {
    log.info('Clearing .deploy_git folder...');
    return fs.emptyDir(deployDir);
  })
.then(() => {
    if (args.all) {
      log.info('Clearing .deploy_git .git... -ksh');
      return fs.rmdirSync(pathFn.join(deployDir, '.git'));
    }
})

更改后的 deploy

deploy:
  - type: git
    branch: master
    repo: <git repo url>
    
  - type: git
+   all: true
    branch: bolg
    repo: <git repo url>

这是修改后的 hexo-deployer-git-ksh