我使用'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
答案 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/