tow*_*owi 5 git git-push git-subtree
我有一个很大的主项目,其中有几个目录作为子树。
我想将一个特定子树中的更改推送到其原点,这是一个单独的存储库。
问题似乎是,我想要推送的当前子树最初并不是来自我想要推送的存储库。它来自不同的 repo,通过我通过谷歌搜索找到的子树指南。它看起来非常相似。
大项目布局,important_subtree我担心的事情在哪里。
~/devel/bigproject
.git/
some_subtree/
other_subtree/
important_subtree/
abc.txt
efg.txt <--- new version
hij.txt
Run Code Online (Sandbox Code Playgroud)
并且important_subtree与该回购“密切相关”:
~/devel/important
.git/
abc.txt
efg.txt <--- old version
hij.txt
Run Code Online (Sandbox Code Playgroud)
现在~/devel/bigproject/important_subtree/efg.txt发生了变化,我想将 important_subtree 推送到 repo 上~/devel/important。所以后来~/devel/important/efg.txt也有变化。
我设法做的唯一的事情是推动推动一切在bigproject为重要,这显然不是我想要的。应该只推送子树中的更改。
这不再那么复杂,您只需在存储库的克隆上使用git filter-branch命令来剔除您不需要的子目录,然后推送到新的远程目录。
git clone <ORIG_REPO_DIR> <NEW_REPO_DIR>
cd <NEW_REPO_DIR>
git filter-branch --prune-empty --subdirectory-filter <THE_SUBDIR_TO_MAKE_NEW_ROOTDIR> master
git push <MY_NEW_REMOTE_ORIGIN_URL> -f .
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5323 次 |
| 最近记录: |