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

标签 c# git unity-game-engine

我在移动提交中使用“rev-list [remote_branch] --count”值作为内部版本号,但希望从该值中检索提交哈希 ID 以供日后引用。

下面是我用来检索 rev-list 计数的 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

最佳答案

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

按如下方式获取提交哈希:

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

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

关于c# - GIT - 是否可以从 'rev-list [remote_branch] --count' 值检索提交哈希?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26515656/

相关文章:

c# - 编写单元测试 : How to get folder with testfiles programmatically

git - 由于特殊字符 "Ã",无法删除 GIT 标签

git - 来自 msysgit(也称为 Windows 上的 Git)的 MinGW 和来自 MinGW.org 的 MinGW 之间的区别

ios - 如何手动将文件放入iOS持久数据路径?

java - Unity3D - 构建播放器时出错 : Win32Exception:

c# - Unity 5 游戏对象序列化

c# - None=1 在以下枚举类中指的是什么?

c# - 检查字符串中的无效字符?最聪明的方法?

c# - 查号码最简单的方法

eclipse - 如何更改 Eclipse egit merge 工具的 merge 模式?