代码之家  ›  专栏  ›  技术社区  ›  lviggiani

NODEGIT-向特定提交添加注释以存储元数据

  •  0
  • lviggiani  · 技术社区  · 5 年前

    我读过 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]);
            }
    

    我想补充一点 Note 到那

            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()
                });
            }
    

    我该怎么做?

    0 回复  |  直到 5 年前
    推荐文章