owa*_*agh 9 git cherry-pick git-subtree
我正在使用Avery Pennarun的git-subtree,它是git的扩展.
我如何使用git子树从子仓库中挑选一个提交到我的主仓库?另外,在我已经对该前缀进行git子树拉取之后,如何进入子回购历史中的特定提交?
我主要在壁球提交模式下运行它.
如何进入子回购历史中的特定提交?
如果你已经压缩了提交,那么就没有办法,因为壁球会丢失不同的提交.
否则,使用未压缩的子树,您可以导航到子树的任何提交,其具有与创建子树的原始存储库中的哈希相同的哈希.
git subtree(没有壁球)实际上将来自外部存储库的所有相关提交添加到您的存储库中,作为当前仓库中的独立树.当你这样做时,git subtree add你会注意到添加了几个提交(来自外部仓库的所有原始提交)和最后一次合并提交,它将内容从该子树移动到使用该--prefix选项指定的给定目录.简而言之,它从另一个不相关的存储库中检出一个分支,然后通过将所有内容移动到给定的子文件夹中将其合并到当前分支中.
所有这些意味着外部仓库的历史可供您使用,您可以像这样结账,记住通过作为一个完全不同的树,这个结账可能会修改您的工作区的所有内容,这在大项目可能很长.
这将我们带到了第二个:
我如何使用git子树从子仓库中挑选一个提交到我的主仓库?
似乎没有当前支持的"樱桃" git subtree.但考虑到以上所有的含义,可以做到以下几点.
# move yourself to the subtree commit of your choice
git checkout <subtree-hash>
# fetch commits from the subtree repository, to have available the commit you want
# to cherry pick.
git fetch <path-to-remote>
# cherry pick the hash you want
git cherry-pick <cherry-hash>
# move back to your original branch
git checkout <your-branch>
# subtree merge your cherry pick (using the previous HEAD),
# so that it gets moved to the correct location specified by prefix.
git subtree merge --prefix <subtree-prefix> HEAD@{1}
# Since you probably fetched more commits that you needed from
# the remote, you might want to clean those that where not needed
git gc
Run Code Online (Sandbox Code Playgroud)
考虑到在执行此操作后如果您尝试git subtree pull进入子树更新,并且它包含您选择的提交,您将以冲突结束,因为您将在同一位置进行两次更改.
另一个更简单的选项,如果您可以访问原始子树存储库,则可以在分支中选择樱桃,然后只选择git subtree pull该特定分支.
| 归档时间: |
|
| 查看次数: |
4365 次 |
| 最近记录: |