GIT - 是否可以从' rev-list [remote_branch] --count'中检索提交哈希值。值?

时间:2014-10-22 19:35:18

标签: c# git unity3d

我使用'rev-list [remote_branch] --count'值作为移动提交中的内部构建版本号,但是希望从以后的值中检索提交哈希id以供参考。

下面是我用来检索转速列表计数的C#代码:

using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using Debug = UnityEngine.Debug;

public static string GetCommitCountFromCorrespondingRemoteBranch()
{
    string strCommitCount = "";

    Process p = new Process();
    // Set path to git exe.
    p.StartInfo.FileName = GIT_EXEC_PATH;
    // Set git command.
    p.StartInfo.Arguments = "rev-list " + GetRemoteBranchName() + " --count";
    // Set working directory.
    p.StartInfo.WorkingDirectory = Application.dataPath + "/../";
    p.StartInfo.RedirectStandardOutput = true;
    p.StartInfo.UseShellExecute = false;
    p.Start();

    // Pass output to variable.
    strCommitCount = p.StandardOutput.ReadToEnd();

    p.WaitForExit();

    if (string.IsNullOrEmpty(strCommitCount) == true)
    {
        Debug.LogError("UNABLE TO GET BRANCH COMMIT COUNT");
    }

    return strCommitCount;
}

示例返回值:4427

1 个答案:

答案 0 :(得分:2)

我知道这个问题已经有几个月了,但我认为我会发布对我有用的内容,以便其他人有可能的解决方案。

获取提交哈希:

How to retrieve the hash for the current commit in Git?

稍后,我计划将其注入AssemblyInfo文件,如下所述: http://nowfromhome.com/posts/msbuild-add-git-commit-hash-to-assemblyinfo/