简体   繁体   English

如何在TFS Build(Git)中单独获取修改的文件

[英]How to get modified files alone in TFS Build (Git)

I needed to get the modified/new files alone in my TFS build get source task. 我需要在TFS构建获取源任务中单独获取修改后的/新文件。

So far I've found We can disable the Get Source task by defining the variable Build.SyncSources = false 到目前为止,我发现我们可以通过定义变量 Build.SyncSources = false来禁用“获取源”任务

This will Just ignore of getting all the sources, which will eventually make my CopyFile Task to Fail since it using the $(Build.SourcesDirectory) as the source 这将忽略所有源,最终将使我的CopyFile Task失败,因为它使用$(Build.SourcesDirectory)作为源

> 2018-07-28T03:13:46.5709194Z Task         : 
> Copy Files 2018-07-28T03:13:46.5709194Z Description  : Copy files from source
> folder to target folder using match patterns (The match patterns will
> only match file paths, not folder paths) 2018-07-28T03:13:46.5709194Z
> Version      : 2.117.0 2018-07-28T03:13:46.5709194Z Author       :
> Microsoft Corporation 2018-07-28T03:13:46.5709194Z Help         :
> [More Information](https://go.microsoft.com/fwlink/?LinkID=708389)
> 2018-07-28T03:13:46.5709194Z
>     ============================================================================== 2018-07-28T03:13:47.1855024Z ##[error]Unhandled: Not found
> SourceFolder: $(Build.SourcesDirectory)

The Question in my Git Source Control there are many files which I don't want all to fetch while Building, Instead of that the files which are modified on that commit/PR merge I need to fetch. 我的Git源代码管理中的问题有许多我在构建时不希望所有人都提取的文件,而不是那些我需要在提交/ PR合并时修改的文件。

How can I achieve this? 我该如何实现?

Once a build server has synced the Git repository it will be able to just fetch the differences between the last build. 一旦构建服务器同步了Git存储库,它将能够获取上一个构建之间的差异。 Since Git relies on the full repository state being present (a commit is a pointer to a state of the working folder which includes all files at that state), it's not possible to just grab the changed files. 由于Git依赖于存在的完整存储库状态(提交是指向工作文件夹状态的指针,该状态包括该状态下的所有文件),因此不可能仅获取已更改的文件。

There is a switch in the Agent Phase step which controls whether the working directory will be cleaned, in which case the agent will have to sync the whole git repo. 代理阶段步骤中有一个开关,用于控制是否将清理工作目录,在这种情况下,代理将必须同步整个git repo。 There's also an option there to only fetch the latest snapshot, instead of the full history: 还有一个选项,仅获取最新快照,而不是完整的历史记录:

控制清理和获取

Shallow Fetch: Allows you to download only the latest snapshot of the repository. 浅提取:仅允许您下载存储库的最新快照。 Will download much faster, but may cause tools like GitVersion to fail (it relies on the history data to calculate a version number). 下载速度会更快,但是可能会导致GitVersion之类的工具失败(它依赖于历史数据来计算版本号)。

Clean: False: will retain the contents of the previous build allowing you to do incremental fetches of sources, incremental builds with tools that support it. 清除:错误:将保留先前构建的内容,使您可以增量获取源代码,并使用支持该构建的工具进行增量构建。 You can combine Clean:False with a custom step which performs more targeted clean up. 您可以将Clean:False与执行更有针对性的清理的自定义步骤结合使用。

If you need the changed files you can issue a git command to copy them from your synced git repo. 如果您需要更改的文件,则可以发出git命令从同步的git repo复制它们。 See: https://stackoverflow.com/a/4126342/736079 . 参见: https : //stackoverflow.com/a/4126342/736079

Alternatively, don't sync the sources and use a custom VSTS Git REST API based script in Powershell to fetch the exact files you're after. 或者,不要同步源,并在Powershell中使用基于VSTS Git REST API的自定义脚本来获取您要查找的确切文件。 See: https://docs.microsoft.com/en-us/rest/api/vsts/git/items?view=vsts-rest-4.1 . 请参阅: https : //docs.microsoft.com/zh-cn/rest/api/vsts/git/items?view=vsts-rest-4.1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM