git - 在 azure 上的 2 个不同存储库之间仅同步单个文件

标签 git azure azure-devops azure-pipelines

我们从事与 azure devOps 作为 Git Repos 连接的项目。有 2 个不同的存储库:repo-A 和 repo-B。

enter image description here

我需要的是,每当我更改任何存储库中的“fileS”(通过提交和推送)时,它应该更新其他存储库中的其他“fileS”以保持两个文件同步。

是否有任何解决方案使用Azure管道自动推送到第二个存储库或任何其他解决方案? 谢谢

最佳答案

Is there any solution using Azure pipeline to automatic push in the second repository or any other solution?

没有直接设置可以做到这一点,但您可以创建一个管道来调用 git 命令以在两个不同存储库之间同步单个文件。

使用触发器设置为 Repo A 创建管道:

enter image description here

然后添加内联powershell任务:

cd $(Agent.BuildDirectory)
git clone https://PAT-H<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="88cddacdc8ecedfea6e9f2fdfaeda6ebe7e5" rel="noreferrer noopener nofollow">[email protected]</a>/{organzition}/{project}/_git/{repo-name}
cd {repo-name}
git checkout branch-name # if the synced file not in master
# Assuming the synced file name is "test.txt" and he exists in the folder "common"
Copy-Item $(Build.SourcesDirectory)\_fileS $(Agnet.BuildDirectory)\{repo-name} -Force
git config --globa user.email "xxxx.com" 
git config --global user.name "xxxxx"
git add common/_fileS
git commit -m "Sync _fileS"
git push

关于git - 在 azure 上的 2 个不同存储库之间仅同步单个文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71605002/

相关文章:

azure-devops - 无法在托管代理上的 azure 管道任务中连接到 localdb

azure - 在 yaml 中使用 if else 和 or 进行多次检查

azure - 致力于自动化以批准来自逻辑应用程序流的拉取请求

git - 如何将不同的分支推送到不同的 heroku 应用程序?

xcode - Xcode 是否向后兼容?Git 是否适用于不同的 Mac 操作系统?

更改文件路径后,git 将文件还原为上一次提交

c# - BotFramework:机器人的 MSA appId 或密码不正确

Azure Cosmos DB - 删除项目时出现 'Request rate is large. More Request Units may be needed' 错误

git - Squash 直接在功能上提交,无需 rebase 或 merge

linux - Linux 上的 Azure Web App - 服务器修补