首页 > 解决方案 > NODEGIT - 向特定提交添加注释以存储元数据

问题描述

我读过git-notes可用于将自定义信息(例如元数据)添加到特定提交,但我找不到如何做到这一点nodegit

目前我正在提交这样的回购,它工作正常

        // git add --all
        let repo = await Git.Repository.open(pathToSomewhere);
        let index = await repo.index();
        await index.addAll();
        await index.write();
        let oid = await index.writeTree();

        // git commit -am ...
        let commitAuthor = Git.Signature.now(authorName, authorEmail);

        if (initial){
            await repo.createCommit("HEAD", commitAuthor, commitAuthor, commitMessage, oid, []);
        } else {
            let head = await Git.Reference.nameToId(repo, "HEAD");
            let parent = await repo.getCommit(head);

            await repo.createCommit("HEAD", commitAuthor, commitAuthor, commitMessage, oid, [parent]);
        }

我想在该提交中添加一个注释并在以后获得所有这样的 repos 提交时能够检索

        let repo = await Git.Repository.open(pathToSomewhere),
            revWalk = repo.createRevWalk();

        revWalk.sorting(Git.Revwalk.SORT.REVERSE);
        revWalk.pushHead(); // places us at the last commit

        let commits = await revWalk.getCommits();
        let history = [];

        for (let co = 0; co < commits.length; co++){
            let commit = commits[co];
            history.push({
                sha: commit.sha(),
                comment: commit.message(),
                author: commit.author().toString(0),
                date: commit.date()
            });
        }

我怎样才能做到这一点?

标签: node.jsgitnodegit

解决方案


推荐阅读