我正在使用Avery Pennarun开发的git子树(git-subtree)作为git的扩展功能。
如何使用git子树(cherry-pick)从子仓库中选择一个提交并合并到我的主要仓库? 在已经对该前缀执行了git子树拉取后,如何在子仓库历史记录中转到特定提交?
我主要在压缩提交模式下运行。
如何使用git子树(cherry-pick)从子仓库中选择一个提交并合并到我的主要仓库? 在已经对该前缀执行了git子树拉取后,如何在子仓库历史记录中转到特定提交?
我主要在压缩提交模式下运行。
git subtree
(没有压缩)会将来自外部存储库的所有相关提交作为独立树添加到您的存储库中。当您执行git subtree add
时,可以注意到添加了几个提交(来自外部存储库的所有原始提交)和一个最后的合并提交,该提交将该子树的内容移动到使用--prefix
选项指定的给定目录中。简而言之,它会从另一个不相关的存储库中检出分支,然后通过将所有内容移动到给定的子文件夹中将其合并到当前分支中。git subtree
目前不支持“cherrypicking”。但是,考虑到上述所有内容,可以执行以下操作。# 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
git subtree pull
更新子树,并且其中包括您挑选的提交,则会出现冲突,因为您将在同一位置进行两次更改。git subtree pull
特定分支即可。
git version 1.8.1
进行了调查,该版本已经包含了子树命令。 - Maic López Sáenz