问题描述
我分叉了一个仓库,克隆它以获得本地副本来处理两个问题。我们称它们为问题1和问题2。首先,我应用了三次提交,解决了问题1中遇到的问题。然后,我执行了 git push origin master
,将更改从本地主分支推送到原点/主设备。在此之后,我发送了一个pull请求来修复问题1.因此问题1的pull请求有三个提交附加到它。
之后,为了解决问题2,我创建了另一个分支通过 git checkout -b upstream upstream / master
来调用 upstream
(我相信这增加了一个远程上游(这是相同的url),并给我一个本地分支上游
,它从 upstream / master
>开头。 p>
现在我做两个提交来解决问题2,用 git cherry-pick< SHA>
(它只是给了我'没有提交'的信息)。在这之后,我做了 git push origin upstream
来填充我的本地上游分支和原始分支的变化。当我向第2期发出新的拉取请求时,第1期的三个提交附加了我为解决第2期提交的两个提交。
(后来我还第四次提交给 origin / master
来解决问题1中的问题,这意味着请求问题1,现在有4个提交附加到它。)
然后在本地我提交了上游分支寻址问题2.我现在想要什么?我希望能够推送此提交,并将此提交更新为第2期的拉取请求,我希望将第1期涉及的4提交和第2期涉及的3提交分开。
现在一切都有点混乱。我是git和github的新手,有人能帮我解决这个问题吗?
这是因为从叉子发出pull request的想法始终是从 master
(或任何其他可以在上游原始回购协议中发展的分支)从
Plus,您不会创建分支名称上游
,您添加一个名为上游
引用您分叉的第一个仓库,以跟踪 upstream / master
(原始仓库中的仓库主)。
请参阅。
我怀疑你的情况是这样的
(master)$ (上游)
- $ - $ - $ - $ - $ - $ - $ - code>
首先::
git branch -m upstream issue2
删除远程上游分支上游
(那将,并且一旦我们已经在本地修复了分支,您将重新制作针对该问题的拉取请求)
git push:upstream
现在,请确保 master
与中的
(也就是从您已分叉的原始仓库)。 master
同步>上游
确保您没有正在进行的工作( reset -
#原始资料库的网址
git remote add上游https://github.com/user/repo
git fetch upstream
git checkout master
git reset --hard upstream / master
这会使您的回购看起来像:
y - y - y(issue2)
现在您需要在重新绑定两个问题分支> master ,以
issue2
开头,以便将它与issue1
分开:git checkout issue2
git rebase --onto master issue1 issue2
然后
issue1
:
git issue1
git rebase master
您可以:
x - x - x(issue1)
/
--o - o - o- -O-O(master,upstream / master)
\
y - y - y(issue2)
现在,您可以推送这两个分支:
git push -f -u原产地问题1
git push -f -u原产地问题2
I have forked a repository, cloned it to get a local copy to work on two issues.Let's call them Issue 1 and Issue 2 . Firstly,I applied three commits which addresses the problem faced in Issue 1. Then I did
git push origin master
to push the changes from my local master branch to origin/master. After this I sent a pull request to fix Issue 1. So Issue 1's pull request has three commits attached to it.After that to address Issue 2, I created another branch called
upstream
viagit checkout -b upstream upstream/master
(I believe this adds a remote upstream (which is the same url as that of origin) and gives me a local branchupstream
which starts off fromupstream/master
).Now I make two commits to address Issue 2, cherry-pick the two commits with
git cherry-pick <SHA>
(which just gave me 'nothing to commit' message). After this I didgit push origin upstream
to populate the changes in my local upstream branch with that in origin. When I sent a new pull request to Issue 2, the three commits of Issue 1 got attached with the two commits I made to address Issue 2. Messing everything up.(Later I also made a 4th commit to
origin/master
to address a problem in Issue 1 which implies the pull request to Issue 1 ,now has 4-commits attached to it.)Then locally I made a commit to upstream branch addressing Issue 2. What do I want now ? I want to be able to push this commit and update this commit to Issue 2's pull request ALONE and I want to separate the 4-commits involved in Issue 1 from the 3-commits involved in Issue 2.
Everything is a bit messed up as of now. I am new to git and github,can someone please help me with this ?
解决方案That is because the idea of making pull request from your fork is always to make them from a dedicated branch, never from
master
(or any other branch which can evolve on the upstream original repo)Plus, you don't create a branch name
upstream
, you add a remote namedupstream
referencing the first repo that you have forked, in order to trackupstream/master
(the master from the original repo).See "Pull new updates from original Github repository into forked Github repository".
At any moment you would then be able to do:
git checkout master git pull upstream master git checkout issue1 git rebase master git push -f origin git checkout issue2 git rebase master git push -f origin
If you had pull requests done for
issue1
andissue2
, thepush -f
(which rewrites the commits of those branches) would trigger an automatic update of your pull request, without you having to do anything.See more at "Couple tips on pull-requests".
I suspect your situation is this
(master) --o--o--o--x--x--x (issue1) \ y--y--y (upstream)
First: rename your "
upstream
" branch:git branch -m upstream issue2
Delete your remote upstream branch named "
upstream
" (that will cancel the associated pull request, and you will remake a pull request for that issue once we have fixed the branch locally)git push :upstream
Now, make sure you have
master
in sync with themaster
fromupstream
(that is, from the original repo you have forked).
Make sure you don't have work in progress (thereset --hard
part would erase it)# url of the original repo git remote add upstream https://github.com/user/repo git fetch upstream git checkout master git reset --hard upstream/master
That will make your repo looks like:
O--O (master, upstream/master) / --o--o--o--x--x--x (issue1) \ y--y--y (issue2)
Now you need to rebase your two issue branches on top of
master
, starting withissue2
, in order to separate it fromissue1
:git checkout issue2 git rebase --onto master issue1 issue2
Then
issue1
:git issue1 git rebase master
You get:
x--x--x (issue1) / --o--o--o--O--O (master, upstream/master) \ y--y--y (issue2)
Now, you can push those two branches:
git push -f -u origin issue1 git push -f -u origin issue2
And make pull requests from there.
这篇关于针对不同的问题发送拉取请求-Github的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!