我有一个本地Git存储库,我创建并使用了几个月。但是,这项工作现在将成为一个具有现有存储库的大型项目的一部分,因此我想将大型项目的服务器作为远程服务器添加,并将我的工作推送到该存储库的子目录中。
然而,我相信这些幼稚的步骤将把我的本地回购推到大型项目回购的顶级目录中:

$ pwd
/home/yotommy/my-local-project
$ git remote add origin git://example.com/gitscn/larger-project.git
$ git push origin master ### goes to top-level directory, not desired!

我试图指定一个子目录(尚未存在):
$ git remote add origin git://example.com/gitscm/larger-project.git/my/sub/dir
$ git push origin master
fatal: '/gitscm/larger-project.git/my/sub/dir' does not appear to be a git repository

我应该先将子目录添加到更大的项目报告中吗?还是有更好的方法?

最佳答案

在@twalberg的带领下,我发现了documentation for subtree merging。这里是这个问题中提出的案例的简明配方。

$ git clone git://example.com/gitscm/larger-project.git
$ git remote add subproj_remote /home/yotommy/my-local-project
$ git fetch subproj_remote
warning: no common commits
remote: Counting objects: 461, done.
remote: Compressing objects: 100% (332/332), done.
remote: Total 461 (delta 157), reused 0 (delta 0)
Receiving objects: 100% (461/461), 272.89 KiB, done.
Resolving deltas: 100% (157/157), done.
From subproj_remote /home/yotommy/my-local-project
 * [new branch]      master     -> subproj_remote/master
$ git checkout -b subproj_branch subproj_remote/master
Branch subproj_branch set up to track remote branch master from subproj_remote.
Switched to a new branch 'subproj_branch'
$ git checkout master
Switched to branch 'master'
$ git read-tree --prefix=subproj/ -u subproj_branch
$ git commit -m "merged subproj"

关于git - 将本地存储库推送到远程存储库的新子目录,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18858709/

10-15 16:56