如何在 TFS 构建期间找到新提交的数量(git) [英] How to find the number of new commits(git) during the TFS Build

查看:39
本文介绍了如何在 TFS 构建期间找到新提交的数量(git)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已按照此解决方案获取文件,这些文件在上次提交时已修改.

I've followed this solution to fetch the files, which are modified in the last commit.

解决方案就像

$files=$(git diff HEAD HEAD~ --name-only)
echo $files
$temp=$files -split ' '
$count=$temp.Length
echo "Total changed $count files"
New-Item -ItemType directory -Path $(Build.ArtifactStagingDirectory)\files
For ($i=0; $i -lt $temp.Length; $i++)
{
  $name=$temp[$i]
  echo "this is $name file"
  if (Test-Path "$(Build.SourcesDirectory)\$name")
    {
      Copy-Item $(Build.SourcesDirectory)\$name $(Build.ArtifactStagingDirectory)\files
    }
}

有了这个,我可以从上次提交中获取修改过的文件,但在我的情况下,可能有 N- 个新提交.

With this, I can able to get the modified files from the last commit, but in my case, there may be N- new commit(s).

所以我看到了一种通过改变 cmd 来实现这一点的方法

So I'm seeing a way to achieve this with change the cmd like

2 次提交

$files=$(git diff HEAD HEAD~2 --name-only)

3 次提交

$files=$(git diff HEAD HEAD~3 --name-only)

诸如此类,

但是,我无法找到一种方法来获取 Build 定义中的新提交数

However, I couldn't able to find a way to get the no of new commits in the Build definition

我的 TFS Get Sources 总是用最新的提交 id 检出对应的分支

My TFS Get Sources always check out the corresponding branch with the latest commit id

2018-09-08T06:05:35.8623084Z ##[command]git checkout --progress --force e88c5a4bf29a539c515ca0e5fea104799426026e
2018-09-08T06:05:36.3681977Z Previous HEAD position was 40ac471... Updated xxxxxxx

这也使得查找旧的提交 ID 变得困难

Which also makes difficult the find the old commit id's as well

推荐答案

我猜你正在寻找 git rev-list

假设您执行以下步骤:

  • 你是大师
  • 您创建一个修补程序分支:git checkout -b hotfix_1
  • 您修改并提交了一些文件,其哈希值为f3de9ae73e1fb06c23506c
  • 您再次修改并提交.最新的哈希是 4985ead3183df8388cf8e4

此时你比 master 早两次提交,所以这样做

At this point you're two commits ahead of master, so doing

git rev-list HEAD ^master

意思是:列出那些在我的历史中而不是在主人的历史中的提交".

Means: "list those commits that are on my history and not in master's history".

在这种情况下打印

4985ead3183df8388cf8e4
f3de9ae73e1fb06c23506c

(因为按时间倒序列出它们是有意义的).

(because it makes sense to list them in reverse chronological order).

然而这种方法只有在您比较没有发散的分支时才有意义.否则,您将只能获得 HEAD 和最后一个共同祖先之间的提交次数,这并不意味着 master 分支自您当前的 HEAD 发散以来没有任何新的提交.

However this method does only make sense when you're comparing branches that haven't diverged. Otherwise, you will only get the number of commits between your HEAD and the last common ancestor, which does not mean the master branch hasn't had any new commits since your current HEAD diverged.

这篇关于如何在 TFS 构建期间找到新提交的数量(git)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆