如何在无关分支之上重新应用提交? [英] How to re-apply commits on top of unrelated branch?
问题描述
我有一个具有提交线性历史记录的简单存储库,如:
[A] - > [B] - > [C] - > [D] - > [E] ...
我基本上需要删除提交A和B,所以我想我会创建一个新的存储库,并希望实现类似的功能:
[X] - > [C] - > [D] - > [E] ...
因此,我创建了一个新的存储库,手动创建提交X,来自A和B的相关信息,现在需要一个命令,从原始存储库中提交C,D,E等命令,并将它放在我的新提交X之上。
如何做到这一点?
编辑:建议的樱桃挑选方法有两个问题:
- 转移的提交失去了日期。有什么方法可以保留提交日期吗?
- 当我从原始存储库获取master(并且该远程主服务器没有任何与新存储库相同的提交)时,我遇到问题删除那些提取的提交。当我做
git branch -D myoriginalrepo / master
时,它说没有这样的分支存在,而我可以在我的GUI工具中清楚地看到这些提交。
不知道为什么你需要提交日期保持不变,但这里有:
git rebase BE --onto X --committer-date-is-author-date
如果 B..E
与 X $ c不在同一个存储库中$ c>(因为它们可以是如果您创建了新的开始您需要首先获取它们:
git fetch< path_to_old_repos>
当然, B
, E
和 X
在这里表示它们的提交标识,如果你没有实际标记/分支它们。 您也可以通过在您的 A
中重新设置类似的东西(尽管提交日期不会被保留)原始存储库和压缩 B
到它:
git rebase -i` A`
#将pick b改为squash b
您将有机会更改提交消息,您可以在此处更改 X
的。
I have a simple repository with linear history of commits, like:
[A] -> [B] -> [C] -> [D] -> [E] ...
I basically need to remove commits A and B so I thought I'd create a new repository and would like to achieve something like:
[X] -> [C] -> [D] -> [E] ...
So I created a new repository, manually created commit X that takes stores the relevant information from A and B and now need a command that will bring commits C, D, E etc. from the original repository and will put it on top of my new commit X.
How to do that?
Edit: Two problems I have with the suggested cherry-pick method are:
- Transferred commits lost their dates. Is there any way to preserve commit dates?
- When I fetched master from the original repository (and that remote master doesn't have any commit in common with the new repository), I have trouble deleting those fetched commits. When I do
git branch -D myoriginalrepo/master
, it says that no such branch exists while I can clearly see those commit in my GUI tool.
Not sure why you need the commit date to stay the same but here goes:
git rebase B E --onto X --committer-date-is-author-date
If B..E
aren't in the same repository as X
(as they can be if you create your fresh start in-place), you'll need to fetch them first:
git fetch <path_to_old_repos>
Of course, B
, E
and X
here mean their commit-ids if you haven't actually tagged/branched them.
You can also do something similar (although commit date won't be preserved) by rebasing from A
in your original repository and squashing B
onto it:
git rebase -i `A`
# change "pick b" to "squash b"
You'll get a chance to change commit message at which point you could make it X
's.
这篇关于如何在无关分支之上重新应用提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!