Git 推送到远程存储库上的特定文件夹

Git push to specific folder on remote repository

如何推送到远程存储库中的特定文件夹?我的本地 C 盘上有以下结构:

myfolder/
    .git
    folder1
    folder2
    folder3
    folder4
    .gitignore

我在此文件夹中执行了 git init 命令。之后我做了 git add . 然后 git commit -m "My first commit" 现在我想将它推送到包含类似结构的 VSTS remote 存储库:

https://helloworld.visualstudio.com/VSTS_folder/_git/VSTS_folder

VSTS_folder/
   greenFolder
   redFolder
   blueFolder
   blackFolder
   yellowFolder
   .gitignore
   README.md

其中 VSTS_folder 是存储库的名称。 greenFolderredFolderyellowFolder 中已经有一些代码。我想做的是将我的本地内容推送到空的 blackFolder 远程文件夹。我试图避免弄乱回购协议并将我的东西推到根目录。我正在使用 git remote add origin https://helloworld.visualstudio.com/VSTS_folder/_git/VSTS_folder/blackFolder 但那没有用。实现此目的的适当 git 命令是什么?谢谢。

那不是 Git 的工作方式。您有一个名为 VSTS_folder 存储库 。创建该存储库的人不了解 Git 存储库是什么。

您需要克隆 存储库,这将为您提供整个存储库的副本。然后你可以向它添加额外的代码。

如果所有这些文件夹都包含完全独立的项目,它们之间没有任何共享,那么您应该考虑将它们拆分成单独的存储库。

坐下来阅读 Git 教程以更好地理解这些概念,您也会受益匪浅。

对于 Git 版本控制系统,它通过 分支 将更改推送到远程仓库(而不是像 svn VCS 这样的文件夹)。

因此您需要将本地内容移动到 blackFolder,并从远程仓库(VSTS git 仓库)拉取更改,最后将分支推送到 VSTS git 回购.

详细步骤如下:

# In your local git repo
rm -Rf .git #it's uncessary to commit at first in your local repo
git init
git remote add origin https://helloworld.visualstudio.com/VSTS_folder/_git/VSTS_folder -f
mkdir blackFolder
mv * blackFolder
mv .gitignore blackFolder
git pull origin master
git add .
git commit -m 'add local stuff to remote repo blackFolder'
git push -u origin master

现在本地内容被推送到 blackFolder 下的 VSTS git 存储库。

git add .\<folder name>
git push

这应该就是您所需要的。我刚刚做到了