如何检索gitlab中下一次提交的SHA?

问题描述 投票:0回答:1

我需要将最新的提交 sha 显示为应用程序版本的一部分,然后提交它。如果我得到最后一个 sha 并保存它,然后提交它,这意味着还有另一个提交 sha ...,所以就像我需要获取下一次提交的 sha 一样。我正在用 c# 编码,这就是我尝试过的:

ProcessStartInfo processInfo = new ProcessStartInfo
            {
                FileName = "git",
                Arguments = "rev-parse --short HEAD",
                RedirectStandardOutput = true,
                UseShellExecute = false,
                CreateNoWindow = true
            };
            using (Process process = new Process { StartInfo = processInfo })
            {
                
                process.Start();
                string commit= process.StandardOutput.ReadToEnd().Trim();
                process.WaitForExit();
                Trace.WriteLine(commit);

它不起作用。而且我不知道 hooks 文件夹中的 bash 文件是否可以在 Windows 上运行(prepare-commit-msg.sample)。

c# git gitlab commit
1个回答
0
投票

结帐未部署。查找

git archive
export-subst
属性:您可以将导出的提交 ID 替换到存档中。以下是 Pro Git 书籍,免费在线中的一些示例,说明您可以使用它来做什么:

导出文件进行部署时,您可以应用 git log 的格式 以及对标记的文件的选定部分进行关键字扩展处理 具有export-subst 属性。

例如,如果您想在您的文件中包含一个名为

LAST_COMMIT
的文件 项目,并自动拥有有关上次提交的元数据 当 git archive 运行时注入它,你可以例如设置 你的
.gitattributes
LAST_COMMIT
文件如下:

LAST_COMMIT export-subst
$ echo 'Last commit date: $Format:%cd by %aN$' > LAST_COMMIT 
$ git add LAST_COMMIT .gitattributes 
$ git commit -am 'adding LAST_COMMIT file for archives'

当你运行 git

archive
时,存档文件的内容将会显示 像这样:

$ git archive HEAD | tar xCf ../deployment-testing - 
$ cat ../deployment-testing/LAST_COMMIT
Last commit date: Tue Apr 21 08:38:48 2009 -0700 by Scott Chacon

替换可以包括例如提交消息和任何 git Notes、git log 可以做简单的自动换行:

$ echo '$Format:Last commit: %h by %aN at %cd%n%+w(76,6,9)%B$' > LAST_COMMIT
$ git commit -am 'export-subst uses git log'\''s custom formatter

git archive uses git log'\''s `pretty=format:` processor
directly, and strips the surrounding `$Format:` and `$`
markup from the output. '
$ git archive @ | tar xfO - LAST_COMMIT
Last commit: 312ccc8 by Jim Hill at Fri May 8 09:14:04 2015 -0700
       export-subst uses git log's custom formatter

         git archive uses git log's `pretty=format:` processor directly, and
         strips the surrounding `$Format:` and `$` markup from the output.

生成的存档适合部署工作,但与任何其他存档一样 导出的存档不适合进一步的开发工作。

© www.soinside.com 2019 - 2024. All rights reserved.