How to push & merge specific commit history?

杀马特。学长 韩版系。学妹 提交于 2019-12-11 07:44:35

问题


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.

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.

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).

Say SubProj has this history, and it is local:

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

Will push A--B--C to the remote.

But:

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

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


回答1:


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 >

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 --onto other_branch D 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.



来源:https://stackoverflow.com/questions/50182309/how-to-push-merge-specific-commit-history

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!