tags:

views:

655

answers:

2

i'm working on 2 different branches release and development.
now i noticed i still need to integrate some changes that were committed to the release branch back into the development branch.
the problem is i don't need all of the commit. only some hunks in certain files. so a simple

git cherry-pick bc66559

does not do the trick.
when i do a

git show bc66559

i can see the diff but don't really know a good way of applying that partially to my current working tree.
any suggestions would be very welcome!

+9  A: 

The core thing you're going to want here is git add -p (-p is a synonym for --patch). This provides an interactive way to check in content, letting you decide whether each hunk should go in, and even letting you manually edit the patch if necessary.

To use it in combination with cherry-pick:

git cherry-pick -n <commit>   # get your patch, but don't commit (-n = --no-commit)
git add -p                    # make all your choices
git commit                    # make the commit!

(Thanks to Tim Henigan for reminding me that git-cherry-pick has a --no-commit option!)

You can of course provide specific paths to add -p if necessary. If you're starting with a patch you could replace the cherry-pick with apply.

Jefromi
You could skip the `reset HEAD^` step by running `git cherry-pick --no-commit`.
Tim Henigan
wow...that was fast!thanks a lot! that did the trick for me. maybe one thing to add from my side: since i did not need most of the changes i did a `git add -i` after the cherry-pick and all in the end a `git reset --hard` to get rid of the changes i didn't want.
oliver
Ah, good call. Forgot you'd need to wipe some changes back out afterwards.
Jefromi
A: 

Assuming the changes you want are at the head of the branch you want the changes from, use git checkout

for a single file :

git checkout branch_that_has_the_changes_you_want path/to/file.rb

for multiple files just daisy chain :

git checkout branch_that_has_the_changes_you_want path/to/file.rb path/to/other_file.rb
Jay Swain
true. it doesn't even have to be at the head of a branch since you can use the sha1 of the commit.one drawback is that it is a little more complicated once you have a certain numbers of files to merge in. i can find out what files where changed with: `git diff --name-only bec143c735ce1b bec143c735ce1b~1`but if there are plenty of them that's kind of awkward.
oliver