美文网首页
git subtree 的命令和使用说明

git subtree 的命令和使用说明

作者: 魔主恋上九尾狐 | 来源:发表于2020-07-01 16:30 被阅读0次

git subtree add --prefix=<prefix> <commit>

git subtree add  --prefix=<prefix> <repository> <ref>

git subtree pull  --prefix=<prefix> <repository> <ref>

git subtree push  --prefix=<prefix> <repository> <ref>

git subtree merge --prefix=<prefix> <commit>

git subtree split --prefix=<prefix> [OPTIONS] [<commit>]

例如:

一、 先准备仓库:

一个仓库叫photoshop,一个仓库叫libpng,然后我们希望把libpng作为photoshop的子仓库。

photoshop的路径为https://github.com/test/photoshop.git,仓库里的文件有:

libPNG的路径为https://github.com/test/libpng.git,仓库里的文件有:

libpng

    |

    |-- libpng.c

    |-- libpng.h

    \-- README.md

//----------------------------------------------------

libPNG的路径为https://github.com/test/libpng.git,仓库里的文件有:

libpng

    |

    |-- libpng.c

    |-- libpng.h

    \-- README.md

二、 在父仓库中新增子仓库:

执行以下命令把libpng添加到photoshop中:

git subtree add --prefix=sub/libpng https://github.com/test/libpng.git master --squash

(--squash参数表示不拉取历史信息,而只生成一条commit信息。)

执行git status可以看到提示新增两条commit:

git log查看详细修改:

执行git push把修改推送到远端photoshop仓库,现在本地仓库与远端仓库的目录结构为:

photoshop

    |

    |-- sub/

    |  |

    |  \--libpng/

    |      |

    |      |-- libpng.c

    |      |-- libpng.h

    |      \-- README.md

    |

    |-- photoshop.c

    |-- photoshop.h

    |-- main.c

    \-- README.md

注意:当你git clone或者git pull的时候,你拉取到的是整个photoshop(包括libpng在内,libpng就相当于photoshop里的一个普通目录);当你修改了libpng里的内容后执行git push,你将会把修改push到photoshop上。也就是说photoshop仓库下的libpng与其他文件无异。

三、 从源仓库拉取更新:

如果源libpng仓库更新了,photoshop里的libpng如何拉取更新?使用git subtree pull,例如:

    git subtree pull --prefix=sub/libpng https://github.com/test/libpng.git master --squash

四、 推送修改到源仓库

如果在photoshop仓库里修改了libpng,然后想把这个修改推送到源libpng仓库呢?使用git subtree push,

git subtree push --prefix=sub/libpng https://github.com/test/libpng.git master

五、 简化git subtree命令

我们已经知道了git subtree 的命令的基本用法,但是上述几个命令还是显得有点复杂,特别是子仓库的源仓库地址,特别不方便记忆。

这里我们把子仓库的地址作为一个remote,方便记忆:

git remote add -f libpng https://github.com/test/libpng.git

然后可以这样来使用git subtree命令:

git subtree add --prefix=sub/libpng libpng master --squash

git subtree pull --prefix=sub/libpng libpng master --squash

git subtree push --prefix=sub/libpng libpng master

相关文章

  • git subtree 的命令和使用说明

    git subtree add --prefix= git subtree add --...

  • git subtree

    git subtree 1.在A项目中添加一个远程连接如下: 2.使用subtree命令添加需要依赖的远程仓库 3...

  • git subtree 的使用

    参考:Git Tools - Subtree MergingThe power of Git subtreegit...

  • git merge two repos

    git clone git_linkFirstly add subtree, from which you wan...

  • Git依赖subtree

    Git依赖——subtree  与submodule相比,subtree的优势在于主项目与子模块的双向 通信,即主...

  • git subtree常用命令

  • git subtree

    使用GIT SUBTREE集成项目到子目录 使用场景 例如,在项目Game中有一个子目录AI。Game和AI分别是...

  • git subtree

    在生成gitHub page ,打算将打包的doc 文件单独作为一个github page 分支时候了解到一个gi...

  • 版本库之间的依赖

    Git submodule和Git subtree 与子模块之间的依赖 对于子模块来说,其模块版本库可以被嵌入到主...

  • git commit 使用及规范

    git commit 使用说明 1 概述 git提交推荐使用命令行工具,请严格遵循提交格式。 2 提交格式 在您g...

网友评论

      本文标题:git subtree 的命令和使用说明

      本文链接:https://www.haomeiwen.com/subject/lyhhqktx.html