node.js - NodeGit如何获取另一个分支的最后提交ID?

标签 node.js nodegit node-github

我有两个分支从我的系统 Master 和 Dev 中 checkout 。

我的工作目录是 Master 从 Master 我想在知道差异后将文件推送/合并到 dev。

例如,在 Master 中,我正在处理 abc.txt 文件,我想检查 dev 中存在的文件与 master 中存在的文件之间的差异。 我该怎么做?

收到此错误

error while pushing == Error: no reference found for shorthand 'dev' (node:93479) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: no reference found for shorthand 'dev'

代码

differenceCommit(fileName,branchName) {
        return new Promise(function (resolve,reject) {
            let repo,
                changes;
            open("./master")
                .then(function (repoResult) {
                    repo = repoResult;
                    return repo;
                })
                .then(function (commitId) {
                    return repo.getBranchCommit("dev");
                })
                ///Difference Before Push
                .then(function (commit) {
                    return commit.getDiffWithOptions("dev");
                })
                .then(function (diffList) {
                    console.log("************************");
                });
    }

最佳答案

origin/ 添加到分支名称:

differenceCommit(fileName,branchName) {
        return new Promise(function (resolve,reject) {
            let repo,
                changes;
            open("./master")
                .then(function (repoResult) {
                    repo = repoResult;
                    return repo;
                })
                .then(function (commitId) {
                    return repo.getBranchCommit("origin/dev");
                })
                ///Difference Before Push
                .then(function (commit) {
                    return commit.getDiffWithOptions("origin/dev");
                })
                .then(function (diffList) {
                    console.log("************************");
                });
    }

关于node.js - NodeGit如何获取另一个分支的最后提交ID?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45712721/

相关文章:

node.js - 如何通过nodegit添加目录或目录中的所有文件?

base64 - 使用 GitHub API 下载文件时解码 base64

javascript - 如何防止javascript一次打开太多文件?

JavaScript - 遍历对象以查找特定键值

android - Cordova 添加平台失败,异常不受支持的 major.minor 版本 52.0

javascript - Uncaught ReferenceError : date is not defined | JavaScript NodeJs jQuery FileSystem

javascript - 如何使用nodegit获取当前分支名称?