我使用git subtree
如下:
git subtree add \
--prefix=directory_destination_path \
--squash [email protected]:kicaj/projectname.git \
master
字符串
但是在directory_destination_path
中,它从projectname.git
复制整个repo。
如何仅将projectname.git
中的文件或目录复制到directory_destination_path
?
此外,我如何更新(自动)文件更改在两个仓库仍然是相同的?这是可能的吗?
3条答案
按热度按时间v09wglhw1#
如果我理解的话,你似乎只想在不同仓库的某个目录中合并,并且你希望它是你仓库中的一个子树。我将在project.git中调用感兴趣的目录
path_of_interest_in_project
,并在你的仓库中调用目标directory_desination_path
。尝试将远程project.git添加为远程,然后在本地 checkout 它的一个分支。然后使用
git-subtree split
只拆分出您感兴趣的project.git目录。之后使用子树合并将其合并到您的repo中。字符串
分支project_master现在应该存储了你的project.git仓库的整个历史。
然后你需要使用
git-subtrees-split
进程。型
现在应该有一个名为
temp_branch
的分支,其中只包含您感兴趣的目录。现在您可以执行git-subtree-merge
将其全部带入您的存储库。型
这应该在temp_分支中合并到主分支中。
h22fl7wq2#
假设你想在ref
master
处添加一个images/
前缀。假设我们想使用https://github.com/octocat/octocat.github.io.git上的远程主机(注意:如果您指定了一个与named ref无关的sha1,则GitHub在以下
fetch
命令中返回error: Server does not allow request for unadvertised object
)从您希望添加子树的分支开始,让我们首先获取所需的提交历史并 checkout 我们的新分支
字符串
接下来,让我们创建一个新的历史,其中只存在我们想要的前缀(
images/
)下的文件。型
最后,让我们将这个子树添加到我们想要的分支(可能是您所在的最后一个分支,
git checkout -
)型
现在你应该在当前分支上拥有了所有想要的文件,并拥有完整的git历史记录。
Alt Squashed历史
有时候,你希望我们子树中的提交被压缩成一个提交。这在一定程度上违背了添加子树的目的,但它有它的位置。下面是上面描述的限制历史拉入你的仓库的变体。
从您希望添加子树的分支开始:
型
注意:我们在上面指定了
--depth=1
,因为我们使用的--squash
是下面的git subtree split
命令。型
toiithl63#
这是一个来自@eddiemoya的great answer,但是有些命令到今天为止还不起作用。所以我只是把它们重新发布在这里:
字符串