当前位置: 动力学知识库 > 问答 > 编程问答 >

git - Cant do a pull request across forks so how do I get my changes in?

问题描述:

So Im new to Git, hence a lot of my terminology might be off here

  1. So there is a Main repository, lets call it "Mainline"
  2. My teammate and I forked Mainline to develop features independently . Lets call these "teammatefork" and "myfork"
  3. Ocassionally we perform a pull request on our forks to add our changes into Mainline
  4. Recently I added a bunch of code to "myfork" which is essentially code to build a test harness. We decided to fork "Mainline" again to "TestHarness" to commit this stuff
  5. I just realized I cant perform a pull request on "myfork" to merge changes into "TestHarness"

Is the right thing here to do a 'rebase'? - im not quite sure, but it sounds right. Essentially I want to get my changes from myfork into the TestHarness fork and both of these are forks of Mainline

And then I would like to go back 2 revisions onto my fork, so Im back where I began before adding the test harness code

Can someone point out what the git magic is required to do this?

网友答案:

If I understand the question correctly you have 4 repositories:

  • "Mainline"
  • "MyFork"
  • "TeammateFork"
  • "TestHarness"

You have commits on "MyFork" that you want to "move over" to "TestHarness".

First of all, you may want to rethink the way you are handling forks. Are your TestHarness changes that large that it requires a new repository?

If you are sure that you want to continue with your path, I think I would do as follows:

I would first go to your "TestHarness" repository and add your "MyFork" as a remote repository and fetch its data:

git remote add myfork myfork_url
git fetch myfork

Then I would cherry pick your two commits from your "MyFork" repository:

git cherry-pick commit_1_hash
git cherry-pick commit_2_hash

Now you should have your two commits on your "TestHarness" fork.

Go back to your "MyFork" and then move back two steps as follows:

git reset --hard HEAD~2

Note that this will delete your changes permanently on your "MyFork" fork. You can remove the --hard if you want to keep them.

At any time if you want to see the current state of your repository try

git log --graph --decorate --all
分享给朋友:
您可能感兴趣的文章:
随机阅读: