Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Git如何将不同的工作副本推送到不同的裸回购协议_Git_Git Branch_Git Push - Fatal编程技术网

Git如何将不同的工作副本推送到不同的裸回购协议

Git如何将不同的工作副本推送到不同的裸回购协议,git,git-branch,git-push,Git,Git Branch,Git Push,当我试图只将我创建的新文件推送到另一个裸存储库时,我遇到了一个问题 比如说,我有两个裸存储库:repo1.git和repo2.git 我克隆了repo1.git的一个副本,并创建了一个名为test_repo1.txt的新文件 我将test_repo1.txt推送到源(repo1.git) 我现在创建另一个名为test_repo2.txt的文件 我只想将test_repo2.txt从repo1.git工作副本推送到repo2.git存储库 因此,我在repo1.git工作副本下运行了以下命令 gi

当我试图只将我创建的新文件推送到另一个裸存储库时,我遇到了一个问题

比如说,我有两个裸存储库:repo1.gitrepo2.git

  • 我克隆了repo1.git的一个副本,并创建了一个名为test_repo1.txt的新文件

  • 我将test_repo1.txt推送到源(repo1.git)

  • 我现在创建另一个名为test_repo2.txt的文件 我只想将test_repo2.txt从repo1.git工作副本推送到repo2.git存储库

  • 因此,我在repo1.git工作副本下运行了以下命令

    git add test_repo2.txt
    git commit -m "add only test_repo2.txt file to repo2.git"
    git push repo2.git master:master
    
    一旦我执行了上述命令

    我进入了repo2.git工作副本,发现“test\u repo2.txt”文件在那里,但“test\u repo1.txt”文件也在那里,这不是我想要的。我只希望“test_repo2.txt”出现在那里,而不是“test_repo1.txt

    为什么“test\u repo1.txt”文件最终会出现在repo2.git裸存储库中

    你的帮助将非常感激

    谢谢


    Finau

    git
    通过以下分支而不是单个文件推送提交。在本例中,您有两个提交,一个是提交给
    test\u repo1.txt
    ,另一个是提交给
    test\u repo2.txt
    ,但每个都在同一个分支中

    在添加
    test_repo1.txt
    后,当您将
    git推送到
    repo1
    时,该分支只有您对repo1的提交。但是,一旦您执行了git add test_repo2.txt并提交它,

    要完成您想要做的事情,您需要在本地工作副本中有两个分支,我们将它们称为
    branch\u repo1
    branch\u repo2
    。您将
    git将每个分支机构推送到其各自的回购。您的程序如下:

  • git clone repo1
    与之前一样,以及
    git checkout master
    (或任何您想要开始的分支)
  • git checkout-b branch\u repo1
    为您的
    repo1
    更改创建并签出分支
  • git add test_repo1.txt
    git commit
    git push repo1 master
    (将
    master
    替换为
    repo1
    上要推到的任何分支)
  • git checkout master
    再次返回您的起始分支(该分支将没有提交
    test\u repo1.txt
  • 现在重复:
    git checkout-b branch\u repo2
    为您的
    repo2
    更改创建分支
  • git add test_repo2.txt
    git commit
    git push repo2 master
  • 完成了
    repo1 master
    将把提交放在
    branch\u repo1
    分支中,而
    repo2 master
    将把提交放在
    branch\u repo2
    分支中
  • 注意在您的
    git push
    中,您不仅必须指定要推送到哪个回购,还必须指定要推送到哪个分支机构。假设您是从
    master
    在这两个平台上工作,您将希望执行以下操作:

    git push repo1 master # while you have the branch_repo1 branch checked out
    

    这将完成你想要做的事情


    (最后一点注意:我用前缀
    branch\uu
    命名了分支机构,而不仅仅是
    repo1
    repo2
    ,以避免回购名称/分支机构名称模棱两可。您可以随意命名分支机构)。

    嗨,shelhamer,太棒了!!非常感谢你抽出时间。非常感激的伴侣。干杯@最后,没问题!享受git的乐趣。如果您使用较新版本的git,它应该在push@J-16 SDiZ,你能对确切的警告作进一步评论吗?我是不是打命令太匆忙了?
    git push repo2 master # while you have the branch_repo2 branch checked out