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);
});
获取文件提交记录信息
最新推荐文章于 2024-07-13 23:17:47 发布