You are not logged in.

#1 2014-11-01 19:30:43

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,595
Website

git merge to cherry pick commits from a pull request [solved]

I have a pull request comprised of a number of commits.  I'd like to go through them one by one and only merge certain ones but am not knowledge enough to do it.  The help on github suggests the following, but once I create a new branch, and pull down the author's commits, how can I accomplish what I am aiming to do?

Thanks!

Step 1: From your project repository, check out a new branch and test the changes.
git checkout -b jamiesonbecker-master master
git pull git://github.com/jamiesonbecker/pulseaudio-ctl.git master
Step 2: Merge the changes and update on GitHub.
git checkout master
git merge --no-ff jamiesonbecker-master
git push origin master

Last edited by graysky (2014-11-01 19:58:08)


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#2 2014-11-01 19:42:51

ids1024
Member
From: California
Registered: 2013-08-16
Posts: 243
Website

Re: git merge to cherry pick commits from a pull request [solved]

I'm no expert with git, but don't you just run a command like this?

git cherry-pick <commit>

Where <commit> is the commit id you want to cherry pick.


"Only wimps use tape backup: _real_ men just upload their important stuff on ftp, and let the rest of the world mirror it."—Linus Torvalds
s/ftp/git/

https://iandouglasscott.com | https://github.org/ids1024 | https://keybase.io/ids1024

Offline

#3 2014-11-01 19:57:52

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,595
Website

Re: git merge to cherry pick commits from a pull request [solved]

Yes, I get it now... you have to have both branches in the repo, then simply `git cherry-pick xxxxxx` does the trick.  Thanks.


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#4 2014-11-02 23:56:22

Trent
Member
From: Baltimore, MD (US)
Registered: 2009-04-16
Posts: 990

Re: git merge to cherry pick commits from a pull request [solved]

That's one way to do it. You're probably done by now, but for posterity's sake, I would have also considered an interactive rebase: from inside the other (pulled) branch, do "git rebase -i <devel>" where <devel> is your main development branch, or master, or whatever you want the changes to get into[1]. Git opens an editor in which all the local commits are listed in chronological order (one per line), and you can delete them or choose to edit the commit message along with some other fancy tricks. Then the rebase tool keeps track of what you want to do with each commit. When the rebase is done, all you have to do is checkout <devel> and do "git merge <branch>" (which will fast-forward without any intervention, since <branch> is just a set of changes based on <devel>).

Rebasing works best if the two branches diverged fairly recently. If the remote's branch has a long and complex history, it diverged from you a while back, and you only want two or three commits from it, it's a clear win for cherry-picking. But if it's based on your current development branch and you want most of it, but just to tweak a few things, rebase -i will probably be more efficient.

Also, I printed this chart out and have it on my bulletin board at work. It really is quite useful.

[1] You can also rebase onto something else, like (for instance) the last commit you pushed. Then you'll have to merge the pulled branch into your dev branch, or rebase your dev branch onto the pulled branch, to make sure you get all the changes from both branches. Just know that rebasing rewrites history, so don't rebase anything that has already been pushed. Git is very powerful, but complicated smile

Offline

Board footer

Powered by FluxBB