Git如何将不同的工作副本推送到不同的裸仓库
当我尝试将仅创建的新文件推送到不同的裸仓库时遇到问题。Git如何将不同的工作副本推送到不同的裸仓库
说,我有两个纯仓库:repo1.git和repo2.git
我克隆repo1.git的副本,并创建一个名为test_repo1.txt
新文件
我推test_repo1.txt原点
我现在创建一个名为test_repo2.txt 另一个文件我想(repo1.git)推ONLY 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_repo2.txt”文件是存在的,但“test_repo1.txt”文件也存在,这不是我想要的。我只想要“test_repo2.txt”在那里没有“test_repo1.txt”。
为什么 “test_repo1.txt” 文件最终在repo2.git的裸库?
您的帮助将大大appriciated。
感谢
Finau
git
推承诺在以下分支机构,而不是单个文件。在你的情况下,你有两个提交,承诺test_repo1.txt
,承诺test_repo2.txt
,但每个都在同一个分支。
当你git push
到repo1
添加test_repo1.txt
后,分支只有你的提交回购一。但是,一旦你做了git add test_repo2.txt
并提交它,相同的分支现在有两个提交,所以当你推动这两个更改应用于repo2
。
要完成你想要做的事情,你需要在你的本地工作副本中有两个分支,我们称之为branch_repo1
和branch_repo2
。您将git push
每个分支到其各自的回购。你的程序是这样的:
-
git clone repo1
不如以前了,git checkout master
(或者你想从开始任何分支) -
git checkout -b branch_repo1
创建并检查了一个分支你repo1
变化。 -
git add test_repo1.txt
和git commit
和git push repo1 master
再次 -
git checkout master
回到你的出发分支(这不会有承诺的test_repo1.txt
) - 现在重复(由你要推到
repo1
任何分支更换master
):git checkout -b branch_repo2
为您的repo2
更改创建分支。 -
git add test_repo2.txt
和git commit
和git push repo2 master
- 完成。
repo1 master
将在branch_repo1
分支中提交,repo2 master
将提交给branch_repo2
分支。
注意,在你的git push
必须指定不仅其回购但分公司要推到。假设你是从master
在两种工作,你会想做的事:
git push repo1 master # while you have the branch_repo1 branch checked out
和
git push repo2 master # while you have the branch_repo2 branch checked out
这将完成你想要做什么。
(最后说明:我以前缀branch_
命名分支,而不是repo1
和repo2
以避免回购名称/分支名称不明确,您可以任意指定分支名称)。
嗨,谢谢,优秀!非常感谢您的时间。很多appriciated伴侣。干杯! – Finau
@Finau,没问题!玩git。 – shelhamer
如果您使用较新版本的git,它应该在推送 –