zhangsanshi / issue-blog

It's a blog rather than issue
0 stars 0 forks source link

git 找到 git add 后被删除的文件 #57

Open zhangsanshi opened 6 years ago

zhangsanshi commented 6 years ago
const shelljs = require('shelljs');
const objects = shelljs.exec('git fsck --cache --no-reflogs --lost-found --unreachable', {
    silent: true,
}).stdout;
const hashs = objects.split('\n').map((item) => {
    if (item.includes('unreachable blob')) {
        return item.replace('unreachable blob', '').trim();
    }
}).filter((item) => item);

const target = [];
hashs.forEach((hash) => {
    const info = shelljs.exec(`git show ${hash}`, {
        silent: true,
    }).stdout;
    if (info.includes('info.mixin')) {
        target.push(hash);
    }
});
console.log(target);