简体   繁体   中英

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. Did a git commit. This will get a commit id say ABC

2) Now I did a git pull from my upstream. This had a merge conflict and after resolving it created a commit for the same.

3) Now i push these to my origin. 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.

How can i now send only the commit that i did, that is the commit ABC (from step# 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. You'd normally branch off upstream/master (but it could be a different branch if you are not targeting master in your pull request). The command git checkout -b my-feature upstream/master would do the trick - provided those names match the ones you have.

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


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

Anyway, never forget that git rebase is dangerous , and you shouldn't use it if you don't fully understand it . 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM