threads / discuss / 13602

two git-cherry-pick enhancements

Subject: two git-cherry-pick enhancements

## tl;dr

4 messages between May 21, 2008 and May 22, 2008.

replies: 3people: 4as markdown or json

Nico -telmich- Schottelius· May 21, 2008, 16:38 UTC · lore
Hello!

When using git-cherry-pick there are two things missing for me and just wondered how you see it (or maybe have a good solution):

- Apply only parts of the patch which applies to <file ...>:
   I sometimes want to apply patches only to some, but not all
   files the patch introduces
- Interactively selecting which parts to apply:
   I want only 7 out of 10 changes the patch introduces.
   It would help alot, if I could choose which parts I want
   to apply for every part of the patch.
Anything planned like that or did I oversee the right way?
Sincerly
Nico
P.S.: Please CC me on reply, I am not subscribed.
-- 
Think about Free and Open Source Software (FOSS).
http://nico.schottelius.org/documentations/foss/the-term-foss/

PGP: BFE4 C736 ABE5 406F 8F42  F7CF B8BE F92A 9885 188C
Govind Salinas· May 21, 2008, 18:36 UTC · re: Nico -telmich- Schottelius · lore

Re: two git-cherry-pick enhancements

On Wed, May 21, 2008 at 11:38 AM, Nico -telmich- Schottelius <nico-git-20080521@schottelius.org> wrote:

Show 22 quoted lines
> Hello!
>
> When using git-cherry-pick there are two things missing for me and just
> wondered how you see it (or maybe have a good solution):
>
> - Apply only parts of the patch which applies to <file ...>:
>   I sometimes want to apply patches only to some, but not all
>   files the patch introduces
>
> - Interactively selecting which parts to apply:
>   I want only 7 out of 10 changes the patch introduces.
>   It would help alot, if I could choose which parts I want
>   to apply for every part of the patch.
>
> Anything planned like that or did I oversee the right way?
>
> Sincerly
>
> Nico
>
> P.S.: Please CC me on reply, I am not subscribed.
>
You could "git cherry-pick --no-commit <id>" and then "git add -p"
-Govind
Sitaram Chamarty· May 22, 2008, 08:58 UTC · re: Nico -telmich- Schottelius · lore

Re: two git-cherry-pick enhancements

On Wed, May 21, 2008 at 10:08 PM, Nico -telmich- Schottelius <nico-git-20080521@schottelius.org> wrote:

Show 8 quoted lines
> - Apply only parts of the patch which applies to <file ...>:
>   I sometimes want to apply patches only to some, but not all
>   files the patch introduces
>
> - Interactively selecting which parts to apply:
>   I want only 7 out of 10 changes the patch introduces.
>   It would help alot, if I could choose which parts I want
>   to apply for every part of the patch.

Both of these are (often, though not always) signs that commits are not granular enough. Your branch maintainer or developer has combined unrelated things into one commit. In an ideal world, he would put each piece as a separate commit, such that if you pick one of those apart, it doesn't make sense.

This is also usually a sign of someone using a central VCS model (or mental model) on that side.

Unless you have no control over who sends you these commits, you may want to address that also in whatever way possible.

IMO stuff like "git add -a" (and the GUI equivalents) were meant for your own development, so that you can essentially re-write history in a sane sequence after having worked on a complex task.

Regards,
Sitaram
Johannes Schindelin· May 22, 2008, 09:29 UTC · re: Nico -telmich- Schottelius · lore

Re: two git-cherry-pick enhancements

Hi,
On Wed, 21 May 2008, Nico -telmich- Schottelius wrote:
Show 13 quoted lines
> When using git-cherry-pick there are two things missing for me and just 
> wondered how you see it (or maybe have a good solution):
> 
> - Apply only parts of the patch which applies to <file ...>:
>    I sometimes want to apply patches only to some, but not all
>    files the patch introduces
> 
> - Interactively selecting which parts to apply:
>    I want only 7 out of 10 changes the patch introduces.
>    It would help alot, if I could choose which parts I want
>    to apply for every part of the patch.
> 
> Anything planned like that or did I oversee the right way?

Conceptually, this is really not cherry-picking _commits_. For example, the commit message will typically be all wrong if you pick only one change. Also, if I were the author of the original patch, I would not be happy for you to label me author of the cut-down (and possibly invalid) commit.

Therefore I suggest (just like on IRC the other day):
	git show <commit> -- <file(s)> | git apply
possibly followed by
	git add -i
or
	git add -p <file>

Hth, Dscho

← back to recent threads