如何推及合并特定的提交历史记录? [英] How to push & merge specific commit history?

查看:180
本文介绍了如何推及合并特定的提交历史记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将具有所有历史记录的Perpo从Perfoce本地克隆到Git,将其称为SubProj,然后将其推送到远程仓库,并使用该远程仓库将SubProj合并到SuperProj下.

I cloned a Repo from Perfoce into Git locally with all its history, call it SubProj, and then I pushed it to a remote repo, and used that remote repo to merge SubProj under a SuperProj.

无法将部分历史记录从Perforce导入到Git,或者 @all none.无论如何,一切正常,我删除了本地存储库及其远程目录.

There is no way to import part of the history from Perforce to Git, either @all or none. Anyway, It went fine and I deleted the local repo, and its remote.

现在,Perforce软件仓库SubProj有所更改,因此我再次使用所有历史记录克隆了SubProj,我想先推送然后与SuperProj合并,但我不希望整个历史记录(只有新的更改).

Now, there are changes on the Perforce depot SubProj, so I cloned SubProj again with all the history, I want to push then merge with SuperProj but I do not want the whole history (only the new changes).

SubProj具有此历史记录,并且是本地的:

Say SubProj has this history, and it is local:

A--B--C--D--E--F--G--H

A--B--C--D--E--F--G--H

我知道我们可以从最早的提交开始推送,直到特定的提交为止.例如:

I know we can push starting from the oldest commit, and until a specific commit. Ex:

git push SubProjRemote <commit C on master>:master

A--B--C推到遥控器上.

但是:

我只能将E--F--G--H推送到远程存储库吗?

Can I push only E--F--G--H to the remote repo?

我可以全部推送,但仅合并E--F--G--H吗?

Can I push all, but then merge only E--F--G--H?

推荐答案

如果要将分支的特定部分合并到另一个分支,则可以使用rebase的on功能.一旦进入分支并获得所需的提交和额外的提交,就可以运行:

If you want to merge a specific section of a branch into another branch, you can use rebase's onto feature. Once you are on the branch with the commits you want + the extra commits, you can run:

git rebase --onto< branch_to_rebase_off_of>< commit_to_stop_before>< first_commit_to_include>

git rebase --onto < branch_to_rebase_off_of > < commit_to_stop_before > < first_commit_to_include >

在您的示例中,通过H提交E,但不通过A-D提交,您可以运行以下命令,将提交哈希值替换为D和H:

For your example taking commits E through H but not A-D, you can run the following, substituting the commit hash for D and H:

git rebase --on到other_branch D H

git rebase --onto other_branch D H

该分支现在应该具有other_branch的基础,但是它也应该已经应用了提交E到H.然后可以将该分支推到需要的任何地方.

The branch should now have the base of other_branch, but it should have also applied commits E through H. You can then push this branch wherever it needs to go.

这篇关于如何推及合并特定的提交历史记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆