[英]did a git commit, git pull and pushed my changes to the repo. How can i send a Pull request for the one that i committed
I was searching for this across web, but couldn't find a solution. 我在整个网络上进行搜索,但是找不到解决方案。 Here is my scenario,
这是我的情况
1) I did my local changes. 1)我做了本地更改。 Did a git commit.
进行了git commit。 This will get a commit id say ABC
这将得到一个提交ID说ABC
2) Now I did a git pull from my upstream. 2)现在我从上游进行了git pull。 This had a merge conflict and after resolving it created a commit for the same.
这有一个合并冲突,解决后,创建了一个相同的提交。
3) Now i push these to my origin. 3)现在我把这些推到我的原点。 From the origin i have to send a Pull request to my upstream.
从原点开始,我必须向我的上游发送拉取请求。
4) While trying to send a Pull request, I see both these commits. 4)在尝试发送Pull请求时,我看到了这两个提交。
How can i now send only the commit that i did, that is the commit ABC (from step# 1) 现在如何仅发送我所做的提交,即提交ABC(来自步骤1)
Pull requests are made between branches - you ask the target repo's owner to pull one of your branches to one of his. 在分支之间进行拉取请求-您要求目标存储库的所有者将您的一个分支拉到其之一。
If you want to make a pull request consisting in just a single commit, then you have to get a branch that only differs in that commit with the target one. 如果要发出仅包含一次提交的拉取请求,则必须获得一个分支,该分支仅与目标提交不同。
The best thing you can do now, I think, is git fetch
your upstream remote, and then create a branch starting from one of it's branches. 我认为,您现在可以做的最好的事情是
git fetch
您的上游远程服务器,然后从其中一个分支开始创建一个分支。 You'd normally branch off upstream/master
(but it could be a different branch if you are not targeting master
in your pull request). 通常,您会分支到
upstream/master
(但是,如果您未在拉取请求中定位master
,则可以是其他分支)。 The command git checkout -b my-feature upstream/master
would do the trick - provided those names match the ones you have. git checkout -b my-feature upstream/master
可以解决问题-只要这些名称与您的名称匹配。
If that worked, you're now on a brand new branch called my-branch
, that points to the very same commit your upstream
's master
branch points to. 如果这行得通,那么您现在位于一个名为
my-branch
全新分支上,该分支指向upstream
的master
分支指向的同一提交。 At this moment, you can git cherry-pick
that single commit you wanted to appear in the PR (or you could manually edit the files and git commit
again, as you'd prefer - the key is you get your commit done over there). 此时,您可以
git cherry-pick
您想要出现在PR中的单个提交(或者您可以根据需要选择手动编辑文件并再次git commit
-关键是您可以在那里完成提交) 。 And now, as you have this new commit in the feature branch, git push
your branch to your own repo (say, git push origin my-feature
). 现在,当您在feature分支中具有此新提交时,
git push
您的分支git push
送到您自己的仓库(例如, git push origin my-feature
)。 That would create (if it didn't exist, which would be the best) the my-feature
branch in your origin
repository, and now you can go create the pull request from my-feature
to the master
branch in upstream
. 这样会在
origin
存储库中创建(如果不存在,那将是最好的) my-feature
分支,现在您可以创建从my-feature
到upstream
master
分支的拉取请求。
From what you tell, the problem seems to be that you git pull
ed your branch - creating that merge commit - instead of using git rebase
. 据您所知,问题似乎在于您
git pull
分支-创建了合并提交-而不是使用git rebase
。 That way, git would automatically tried to cherry-pick
your commit on top of the target branch (say, upstream/master
), and there wouldn't have appeared any merge commit. 这样,git会自动尝试在目标分支(例如,
upstream/master
)上cherry-pick
您的提交,并且不会出现任何合并提交。
Anyway, never forget that git rebase is dangerous , and you shouldn't use it if you don't fully understand it . 无论如何,永远不要忘记git rebase是危险的 , 如果您不完全了解它,就不要使用它 。 You'd better learn more about it first , and then start guessing when and how it would be nice to use it.
你最好了解 更多 关于 它 的第一 ,然后开始猜测何时,怎么会是很好的使用它。
If it has to be just one thing, don't ever forget the rule of thumb: never rebase public commits. 如果这仅仅是一件事,那就永远不要忘记经验法则:永远不要为公共提交重新设置基准。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.