使用git的subtree将已有项目的某个目录分离成独立项目
来源:互联网 发布:vb语言程序设计pdf 编辑:程序博客网 时间:2024/06/11 01:52
git在1.8版本后加入了subtree的功能,这个功能比之前的submodule功能强大很多,而且很好用,还是老版本的赶紧升级下吧。
一些使用方法可参见这个页面: http://aoxuis.me/posts/2013/08/07/git-subtree/
当一个项目在开发若干时间后,希望将某个目录单独出一个项目来开发,此时就可以利用这个subtree的功能分离里。
然而直接用git subtree add 的命令会出现 prefix ‘***’ already exists. 这样的错误提示,
这是因为对应的目录已经存在,不能直接添加,需要按下面的方式把对应的目录剥离开然后再加入subtree
具体的操作方式是这样的:
1. 首先cd到需要处理的项目的目录:
pushd <big-repo>
git subtree split -P <name-of-folder> -b <name-of-new-branch> # 将需要分离的目录的提交日志分离成一个独立的临时版本
popd
git subtree split -P <name-of-folder> -b <name-of-new-branch> # 将需要分离的目录的提交日志分离成一个独立的临时版本
popd
2. 创建一个新的repo
mkdir <new-repo>
pushd <new-repo>
git init
git pull </path/to/big-repo> <name-of-new-branch>
pushd <new-repo>
git init
git pull </path/to/big-repo> <name-of-new-branch>
3. 连接的github
git remote add origin <git@github.com:my-user/new-repo.git>
git push origin -u master
git push origin -u master
其中第2, 3两步也可以直接clone已有的hub,这样做:
git clone <git@github.com:my-user/new-repo.git> <dir-of-tmp-repo>
git pull </path/to/big-repo> <name-of-new-branch>
git push origin -u master
git pull </path/to/big-repo> <name-of-new-branch>
git push origin -u master
4. 清理数据
popd # get out of <new-repo>
pushd <big-repo>
git rm -rf <name-of-folder>
git commit -m '移除相应模块' # 提交删除申请
git branch -D <name-of-new-branch> # 删除临时分支,也可以不移除,自己看情况
pushd <big-repo>
git rm -rf <name-of-folder>
git commit -m '移除相应模块' # 提交删除申请
git branch -D <name-of-new-branch> # 删除临时分支,也可以不移除,自己看情况
5. 添加subtree
git subtree add -P <name-of-folder> <git@github.com:my-user/new-repo.git> master
git push origin master
git push origin master
执行到第3步时,对应的目录已经剥离出来形成独立的项目了。第4,5步主要是把当前项目的对应的文件给删除,可以不执行,以后可以通过
# 更新
git subtree pull -P <name-of-folder> <git@github.com:my-user/new-repo.git> master
# 提交
git subtree push -P <name-of-folder> <git@github.com:my-user/new-repo.git> master
git subtree pull -P <name-of-folder> <git@github.com:my-user/new-repo.git> master
# 提交
git subtree push -P <name-of-folder> <git@github.com:my-user/new-repo.git> master
来执行相应的subtree操作
转自:http://www.queyang.com/blog/archives/519
0 0
- 使用git的subtree将已有项目的某个目录分离成独立项目
- Git Subtree 的使用
- git教程(四)--使用GIT SUBTREE集成项目到子目录
- Git 回退到项目的某个版本
- Git Subtree 的介绍及使用
- Git Subtree 的介绍及使用
- git subtree 的使用方法
- git subtree 的安装
- 使用subtree引入子项目
- 171 git subtree 管理子项目
- Eclipse中选择git 的repository的某个项目,不要使用import,而是要使用新建项目
- 项目中Git的使用
- git检出Coding上某个分支下的项目
- MVC4 Model View Controller分离成独立项目
- 如何在github上下载某个项目的单独某个目录
- Git subtree 日常使用
- fastdfs 新添加一个项目的图片目录 实现独立的上传下载功能
- 使用git来管理自己的项目
- Ugly Number--leetcode
- VC注册表文件关联,图标关联
- activity四种启动模式
- Weblogic、Tomcat、Oracle与Clob
- 2286: [Sdoi2011消耗战|树形DP|虚树
- 使用git的subtree将已有项目的某个目录分离成独立项目
- Cortex M3寄存器组
- 监听ContentProvider数据改变
- 在Visual Studio中使用Beyond Compare
- Python 学习之路(一)
- Android获取微信公众号推送消息历史记录
- 推荐一个Android开发懒人库 -- ButterKnife
- 查询mysql那些表出于死锁状态
- ubuntu 使用Eclipse对FFmpeg进行调试