获取文件提交记录信息

const simpleGit = require('simple-git');
const path = require('path');

// 初始化一个git实例,指向你的仓库
const git = simpleGit({ baseDir: process.cwd() });

// 获取文件的提交记录
git.log(['--', path.resolve(process.cwd(), 'package.json')])
  .then((logOutput) => {
    // logOutput是一个数组,包含了所有的提交记录
    // 你可以遍历数组来查看每个提交的信息
    console.log('logOutput', logOutput);
    logOutput.all.forEach(commit => {
      console.log('hash:', commit.hash); // 提交哈希
      console.log('message:', commit.message); // 提交信息
      console.log('author.name:', commit.author_name); // 作者名字
      console.log('author.email:', commit.author_email); // 作者邮箱
      console.log('timestamp:', commit.date); // 提交时间戳
    });
  })
  .catch((err) => {
    // 处理错误
    console.error('Error getting commit logs:', err);
  });
  • 10
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值