我在移动提交中使用“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/