Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git - Cherry pick a single commit for pull request

Tags:

git

github

I might not have the terminology down yet. I made file to be added to a open project on git. I forked the project. I made some changes and my last commit is the file I want to request to the project and not the small changes I made before hand. When I go to github site and make pull request I get all the commits before the one I want which is last one of a file and I don't' want to submit all of the other commits because I don't think its necessary for the project. Just my own changes. What do I do? Should I just make another res or attach the file singularly and submit, if that's possible.

like image 306
user3590149 Avatar asked Sep 21 '14 04:09

user3590149


People also ask

Can you cherry pick a commit?

Cherry picking is the act of picking a commit from a branch and applying it to another. git cherry-pick can be useful for undoing changes. For example, say a commit is accidently made to the wrong branch. You can switch to the correct branch and cherry-pick the commit to where it should belong.

How do I pull a specific commit in git?

How do I pull a specific commit? The short answer is: you cannot pull a specific commit from a remote. However, you may fetch new data from the remote and then use git-checkout COMMIT_ID to view the code at the COMMIT_ID .

How do I cherry pick just the commits in a pull request?

Turns out you can, indeed, "cherry-pick" just the commits you want from that pull request. Steps: Pull down the branch locally. Use your git GUI or pull it down on the command line, whatever you'd like. Get back into the branch you're merging into. You'll likely do this by running git checkout master.

How do I cherry pick a specific commit in Git?

Find the commits you want to pull into your branch. Go to either the git log or the GitHub UI and grab the unique commit hashes for each of the commits that you want. "Cherry pick" the commits you want into this branch. Run this command: git cherry-pick super-long-hash-here.

How do I pull only specific commits from another branch?

You can grab only specific commits with a very simple git command: git cherry-pick. Git's cherry-pick command allows you to "cherry pick" only the commits you want from another branch. Here are the steps to using it: Pull down the branch locally. Use your git GUI or pull it down on the command line, whatever you'd like.

How to create a GitHub pull request with specific commits?

Simply click Compare & pull request to create a pull request in the repository that you would like to contribute with only the changes you picked. Tada. You have done it=) Hopefully this guide has help you to create a GitHub pull request with a specific commits. Thank you for reading! I’ll try to keep this list current and up to date.


1 Answers

You need to create a fresh branch from the remote HEAD, cherry-pick the commit to that branch, push the branch to your repo on GitHub, then create a pull request.

git checkout -b mybranch
git fetch upstream
git reset --hard upstream/master
git cherry-pick <commit-hash>
git push origin mybranch:mybranch
like image 57
SLaks Avatar answered Oct 19 '22 00:10

SLaks