Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apply a commit chunk by chunk

When I add a file to staging, I can

$ git add my_file -p

And select the chunks I want to stage.

Is there a way to merge/cherry-pick a commit and apply its diff chunk by chunk?

Thanks

like image 707
ms123 Avatar asked Oct 09 '12 12:10

ms123


1 Answers

I'm not aware of a direct way to do this but here's an indirect way.

git cherry-pick -n <commit>

Cherry pick the commit but tell git not to commit it (-n). The changes should now be in your working copy so you can do

git checkout -p

This will iterate over each chunk and ask if you want to discard it, say yes to any chunks you don't want and no to chunks you want to keep.

like image 177
asm Avatar answered Sep 27 '22 02:09

asm