我们从事与 azure devOps 作为 Git Repos 连接的项目。有 2 个不同的存储库:repo-A 和 repo-B。
我需要的是,每当我更改任何存储库中的“fileS”(通过提交和推送)时,它应该更新其他存储库中的其他“fileS”以保持两个文件同步。
是否有任何解决方案使用Azure管道自动推送到第二个存储库或任何其他解决方案? 谢谢
最佳答案
Is there any solution using Azure pipeline to automatic push in the second repository or any other solution?
没有直接设置可以做到这一点,但您可以创建一个管道来调用 git 命令以在两个不同存储库之间同步单个文件。
使用触发器设置为 Repo A 创建管道:
然后添加内联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/