我已经按照这个solution来获取文件,这些文件在上次提交时被修改。
解决方案就像
$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个新提交。
所以我看到了通过改变cmd来实现这一目标的方法
2提交
$files=$(git diff HEAD HEAD~2 --name-only)
3个提交
$files=$(git diff HEAD HEAD~3 --name-only)
像这样。,
但是,我无法找到在Build定义中获取no提交的方法
我的TFS Get Sources
总是检查具有最新提交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
我猜你在寻找git rev-list
假设您执行以下步骤:
git checkout -b hotfix_1
f3de9ae73e1fb06c23506c
4985ead3183df8388cf8e4
在这一点上,你提前两次提交,这样做
git rev-list HEAD ^master
意思是:“列出我历史上而不是主人历史上的那些提交”。
在这种情况下打印
4985ead3183df8388cf8e4
f3de9ae73e1fb06c23506c
(因为以反向的时间顺序列出它们是有意义的)。
但是,当您比较未分叉的分支时,此方法才有意义。否则,您将只获得HEAD和最后一个共同祖先之间的提交次数,这并不意味着master
分支自您当前的HEAD分歧后没有任何新的提交。