使用Powershell从文件中提取Git URL

使用Powershell从文件中提取Git URL,powershell,gitlab,Powershell,Gitlab,1/我需要在文件夹中提取url的特定部分。url位于名为“.git”的子文件夹中,我使用以下命令: git remote get-url --all origin url如下所示: - git@servername:do-amont/production/ei2/nova/migration-devfactory.git - ssh://servername.domain.com:30272/do-amont/production/ei2/nova/migration-devfactory.g

1/我需要在文件夹中提取url的特定部分。url位于名为“.git”的子文件夹中,我使用以下命令:

git remote get-url --all origin
url如下所示:

- git@servername:do-amont/production/ei2/nova/migration-devfactory.git
- ssh://servername.domain.com:30272/do-amont/production/ei2/nova/migration-devfactory.git
- https: //gitlab-review-dev-jxuor3.openshift-intra-dev.domain. com/do-amont/production/ei2/nova/migration-devfactory.git

我需要的部分是

do-amont/production/ei2/nova/migration-devfactory.git
之后,我需要将提取url放在这个命令上

git remote set-url --add origin ssh://git@l203ei3007.domain.com:30272/do-amont/production/ei2/nova/migration-devfactory.git 

我需要在powershell上自动执行这些步骤

您可以通过
git-config
git命令行命令从git-config获取指定远程设备的URL,只要您在带有
.git
文件夹的目录中运行它

因此,您可以这样做(假设您要保留的URL部分始终位于冒号之后):


欢迎来到StackOverflow!你的帖子目前没有包含任何问题-到目前为止你尝试了什么,它是如何失败的,你需要帮助的是什么?你好,Mathias。我的问题是“如何使用脚本powershell自动化这些步骤”?谢谢Mark我尝试将此放在我的脚本上测试它Mark谢谢它使用url以“git@”开头,但我对url以“ssh://”或“https://”开头有问题,因为它们在url中是两个冒号。请问如何从第二个冒号开始???再次感谢你
$GitURL = (git config remote.origin.url).split(':')[1]

git remote set-url --add origin "ssh://git@l203ei3007.domain.com:30272/$GitURL"