我要添加到VSTS中的存储库中的文件夹中有5个本地存储库。
我不介意历史记录是否合并,我只需要将5个全部显示在VSTS的单个存储库中即可。
我在VSTS中创建我的仓库,然后运行以下命令。
git init
git submodule add "./REPO1"
git submodule add "./REPO2"
git submodule add "./REPO3"
git submodule add "./REPO4"
git submodule add "./REPO5"
git commit -m "Adding Submodules"
git remote add origin "MY-GIT-REPO-URL"
git push --set-upstream origin master
我认为这足够了,但是当我从这个仓库中克隆下来时,我得到了文件夹,但是它们是空的。也许我应该以不同于子模块的其他方式来解决这个问题。任何帮助将不胜感激。
这是我克隆存储库时的.gitmodules文件的样子;
[submodule "Repo1"]
path = Repo1
url = ./Repo1
[submodule "Repo2"]
path = Repo2
url = ./Repo2
[submodule "Repo3"]
path = Repo3
url = ./Repo3
[submodule "Repo4"]
path = Repo4
url = ./Repo4
[submodule "Repo5"]
path = Repo5
url = ./Repo5
答案 0 :(得分:0)
如果您不想保留历史记录,那么您要做的就是这样:
git init
git subtree add -P REPO1 ../path/to/REPO1 master
git subtree add -P REPO2 ../path/to/REPO2 master
...
如果需要保留历史记录,则应执行以下操作:
git init
git remote add REPO1 ../path/to/REPO1
git remote add REPO2 ../path/to/REPO2
...
git fetch --all
git subtree add -P REPO1 REPO1/master
git subtree add -P REPO2 REPO2/master
...
答案 1 :(得分:0)
我最终整理了以下Powershell脚本,将所有内容合并为一个git。然后,我git remote add
发布了我的VSTS存储库,并将其推送给管理员。很高兴看到我的所有历史在VSTS中都完好无损!
$MyPath = "LocationOfLocalReposToMerge"
$FolderNames = "Repo1","Repo2","Repo3","Repo4","Repo5"
$Processed = @()
git init
dir > deleteme.txt
git add .
git commit -m “Initial dummy commit”
foreach ($element in $FolderNames)
{
$name = $element -replace '\s',''
$Processed += $element
git remote add -f $name ($MyPath + $element)
"ADDED REMOTE"
git merge $name/master --allow-unrelated-histories
"MERGED"
if ($element -eq $FolderNames[0])
{
git rm .\deleteme.txt
git commit -m “Clean up initial file”
}
mkdir $element
"DIR CREATED"
dir –exclude $Processed | %{git mv $_.Name $element}
"MOVE FILES COMPLETE"
$CommitMsg = “Move " + $element + " files into subdir”
git commit -m $CommitMsg
}
"COMPLETE"