Git克隆存储库位于特定文件夹中,但保留默认文件夹名称

时间:2018-11-28 03:40:48

标签: linux bash git shell clone

所以我正在使用git clone命令,但是当我尝试将存储库克隆到特定文件夹时,它不会像通常那样创建文件夹。 例如,当我这样使用

git clone https://github.com/username/repositoryName.git myFolderName

它将创建一个名为repositoryName的文件夹,并将该存储库存储在其中。当我这样使用它时

fileavhrr <- ".../GLASS02B05.V04.A1990161.2018062.hdf"
filemodis<-".../GLASS02B06.V04.A2013169.2017128.hdf"
gdal_translate(get_subdatasets(filemodis)[10], dst_dataset =
        ".../modis.tif") 
gdal_translate(get_subdatasets(fileavhrr)[8], projwin = c(-180,90,180,50), dst_dataset = ".../avhrr.tif") #ideally I'd only like data north of 50 degrees

avhrr<- raster(".../avhrr.tif")

#class       : RasterLayer 
#dimensions  : 800, 7200, 5760000  (nrow, ncol, ncell)
#resolution  : 0.05, 0.05  (x, y)
#extent      : -180, 180, 50, 90  (xmin, xmax, ymin, ymax)
#coord. ref. : +proj=longlat +ellps=clrk66 +no_defs 
#values      : -32768, 32767  (min, max)

modis<- raster(".../modis.tif")

#class       : RasterLayer   
#dimensions  : 3600, 7200, 25920000  (nrow, ncol, ncell) 
#resolution  : 154.4376, 308.8751  (x, y)  
#extent   : -20015109, -18903159, 8895604, 10007555  (xmin, xmax, ymin, ymax)  
#coord. ref. : +proj=sinu +lon_0=0 +x_0=0 +y_0=0 +a=6371007.181
    +b=6371007.181 +units=m +no_defs   
#values      : -32768, 32767  (min, max)

它没有创建它将创建的默认文件夹。它只是将其保存在myFolderName中。问题是我希望将其存储在该默认文件夹中,但我希望该默认文件夹位于myFolderName中。我无法使用mv命令,因为我不知道默认文件夹名称,而且我同时克隆了很多存储库。有什么想法吗?

谢谢。

3 个答案:

答案 0 :(得分:3)

您应该可以做到,

git clone https://github.com/username/repositoryName.git myFolderName/repositoryName

PS: 这样可以从URL拆分存储库名称

basename -s .git $(echo "https://github.com/username/repositoryName.git")

答案 1 :(得分:2)

那这样的事情呢?

## Your links in an array
declare -a arr=("https://github.com/username/repositoryName" "https://github.com/username/repositoryName2")

## Folder to store each of these git repos
folder=myFolderName

## Go through each link in array
for i in "${arr[@]}"
do
    ## Use basename to extract folder name from link
    git clone $i $folder/$(basename $i)
done

将生成以下git存储库:

myFolderName/repositoryName
myFolderName/repositoryName2

注意:您无需在.git的每个HTTPS链接的末尾添加git clone

如果由于某种原因需要包括.git,可以使用以下方法将其剥离:

git clone $i $folder/$(basename ${i%.*})

答案 2 :(得分:1)

假设myFolderName已经存在,最简单的解决方案是:

git -C myFolderName clone https://github.com/username/repositoryName.git