简体   繁体   English

如何使用git-subtree转到特定的提交?

[英]How do I go to a specific commit using git-subtree?

I am using Avery Pennarun's git-subtree which is an extension to git. 我正在使用Avery Pennarun的git-subtree,它是git的扩展。

How do I cherry-pick a commit from a sub-repo into my main repo using git subtree? 如何使用git子树将子仓库中的提交樱桃拣选到主仓库中? Also how do I go to a specific commit in the history of the sub-repo after I have already done a git subtree pull on that prefix? 另外,在已经对该前缀执行git子树提取之后,如何在子存储库的历史记录中进行特定的提交?

I am primarily running this in the squash commits mode. 我主要是在南瓜提交模式下运行它。

how do I go to a specific commit in the history of the sub-repo? 我如何进入子仓库历史记录中的特定提交?

If you have squashed the commits, then there is no way, since the squash looses the different commits. 如果您已压缩提交,则没有办法,因为南瓜会丢失不同的提交。

Otherwise, with a un-squashed subtree, you can navigate to any commit of the subtree with just the same hash that it has in the original repository from which the subtree was created. 否则,使用未压缩的子树,您可以导航到该子树的任何提交,该提交的散列与创建子树的原始存储库中的散列相同。

git subtree (without the squash) actually adds into your repository all the relevant commits from the external repository as an independent tree within your current repo. git subtree (不包含南瓜)实际上将外部存储库中的所有相关提交作为当前回购中的独立树添加到存储库中。 When you do a git subtree add you can notice that several commits are added (all the original commits from the external repo) and a last merge commit that moves the content from that subtree to the given directory specified with the --prefix option. 当您git subtree add您会注意到git subtree add了多个提交(来自外部存储库的所有原始提交)和最后一个合并提交,该提交将内容从该子树移动到使用--prefix选项指定的给定目录。 In a nutshell, it checks out a branch from another unrelated repository and then merges it into your current branch by moving all that content into a given subfolder. 简而言之,它从另一个不相关的存储库中签出一个分支,然后通过将所有内容移动到给定的子文件夹中将其合并到您的当前分支中。

All this means is that the history of the external repo is available to you, you can checkout to it just like that, having in mind that by being a completely different tree this checkout will probably modify ALL the contents of your workspace, which on big projects can be lengthy. 所有这些意味着您可以使用外部存储库的历史记录,您可以像这样签出,请记住,由于是完全不同的树,此签出可能会修改工作空间的所有内容,这在很大程度上项目可能很长。

This moves us to the second: 这将我们移至第二个:

How do I cherry-pick a commit from a sub-repo into my main repo using git subtree? 如何使用git子树将子仓库中的提交樱桃拣选到主仓库中?

Seems like there is not current "cherrypicking" supported by git subtree on itself. 好像自己的git subtree当前不支持“ cherrypicking”。 But given the implications of all the above the following can be done. 但是,鉴于上述所有含义,可以完成以下工作。

# 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

Take into consideration that after doing this if you try to git subtree pull into your subtree an update, and it includes the commit you cherry picked, you will end with a conflict since you will have two changes in the same place. 考虑到这样做之后,如果您尝试将git subtree pull引入到子树中进行更新,并且其中包括您选择的提交,那么您将以冲突结尾,因为您将在同一位置进行两次更改。

Another more simple option, if you have access to the original subtree repository, is to make the cherry pick there in a branch and then just git subtree pull that specific branch. 如果您有权访问原始的子树存储库,则另一个更简单的选择是在分支中选择樱桃,然后仅git subtree pull该特定分支。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM