1

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?

Sandra K
  • 1,209
  • 1
  • 10
  • 21
  • Are the SHA-1 hashes of the two clones from Perforce identical? With other word, when you migrated again is the hash of `E` the same as it was on the first Migration in the remote repo? – milbrandt May 04 '18 at 20:09
  • @milbrandt I can't verify that, I deleted the repo of the first clone. Now I only have the second clone and it is the whole history as a Git repo. But I know from which date (what commit) I want to start with (Ex `E--F--G--H`). – Sandra K May 04 '18 at 20:10
  • You only deleted it locally. The remote repo of the first migration still exist, doesn't it? – milbrandt May 04 '18 at 20:11
  • @milbrandt No, I deleted both local and remote. I will remove this comment because I had this on OP – Sandra K May 04 '18 at 20:12
  • Your remote project is `SuperProj`. At least is you didn't do a squash commit, all commits of the original `SubProj` should be included there. – milbrandt May 04 '18 at 20:16
  • @milbrandt oh I see, you are correct, I see the whole history of `SubProj` under `SuperProj`. Last commit there was `6fddcf25`. So, from the new clone, I want only the stuff after `6fddcf25`. But, this key commit has a different SHA-1 on the current clone (`a69f1577`) – Sandra K May 04 '18 at 20:22
  • That was the information I asked. Corresponding commits of the migratation have different SHA-1 hashes. The commit `6fddcf25` was the commit before the merge, wasn't it? If it was the merge, please double check for the parents, if one of them has the hash `a69f1577`. If this is the case, it will be easy. Otherwise we have to go the cumbersome way. – milbrandt May 04 '18 at 20:29

1 Answers1

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.

MikeBergerUS
  • 196
  • 12