gpt4 book ai didi

git - 将本地仓库推送到远程仓库的新子目录

转载 作者:IT王子 更新时间:2023-10-29 00:55:37 27 4
gpt4 key购买 nike

我有一个我创建的本地 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com