【问题标题】:Git push to specific folder on remote repositoryGit推送到远程存储库上的特定文件夹
【发布时间】:2018-05-14 20:41:44
【问题描述】:

如何推送到远程存储库中的特定文件夹?我的本地 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 远程文件夹,该文件夹为空。我试图避免弄乱 repo 并将我的东西推到根目录。我正在使用git remote add origin https://helloworld.visualstudio.com/VSTS_folder/_git/VSTS_folder/blackFolder,但这不起作用。实现此目的的适当 git 命令是什么?谢谢。

【问题讨论】:

    标签: git azure-devops directory push


    【解决方案1】:

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

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

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

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

    【讨论】:

    • 我有 iOS 项目,当我推送我的代码时,它说 repo 大小超过 100mb。现在我在 gitignore 中添加了 pod 仍然收到相同的消息。你能建议我如何推送我的完整代码
    • @Chandni 这是一个完全不相关的问题。如果您有新问题,请提出新问题。
    【解决方案2】:

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

    所以你需要将本地内容移动到blackFolder,并从远程仓库(VSTS git repo)拉取更改,最后将分支推送到VSTS git repo

    详细步骤如下:

    # 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 repo。

    【讨论】:

      【解决方案3】:
      git add .\<folder name>
      git push
      

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

      【讨论】:

        猜你喜欢
        • 2020-11-27
        • 2011-01-29
        • 2013-01-27
        • 2018-06-24
        • 2010-10-25
        • 1970-01-01
        • 2014-10-21
        • 1970-01-01
        相关资源
        最近更新 更多