On Sun, 24 Jul 2016 23:26:20 -0700
Michael <keybou...@gmail.com> wrote:

> How do I move a *change* (instead of a whole file) from one branch to
> another?
> keybounceMBP:realisticfluids michael$ git diff stash^1 stash --
> RealisticFluids.java diff --git
> a/src/main/java/com/mcfht/realisticfluids/RealisticFluids.java
> b/src/main/java/com/mcfht/realisticfluids/RealisticFluids.java index
> ca1bbb5..343bbeb 100644
> --- a/src/main/java/com/mcfht/realisticfluids/RealisticFluids.java
> +++ b/src/main/java/com/mcfht/realisticfluids/RealisticFluids.java
> @@ -613,6 +613,7 @@ public class RealisticFluids extends
> DummyModContainer // if (map.distant.size() < 256)
>                          // System.out.println("Added eeet");
>                          map.distant.add(c);
> +                    map.chunks.remove(c);
>                  }
>              }
>          }
> There is a single patch in one file in that stash that needs to be
> promoted to develop. Everything else in that stash (so far) is
> debugging, one refactoring has happened (so the other stuff in the
> file won't even apply), and there would be a known merge conflict if
> I tried.
> Now, this is an absolutely trivial item, and I can apply this line by
> hand. But git should not be about doing this by hand. I figure
> there's a way to do this that I don't know.

The question is a bit vague in terminology.

Git does not store patches, it only ever stores commits, and patches
are generated on-the-fly by various tools intended to display changes
to the user (such as `git diff` etc).

The command which takes specified commits or commits from anywhere and
applies them to the currently checked out branch is `git cherry-pick`.

If you want to cherry-pick a stashed commit, two minor twists are
requred as a stash entry is itself a merge commit with its first
parent being the tip commit of the branch which were the HEAD when the
stash was recorded:

1) Pass `git cherry-pick` the "-m 1" command-line option so that it
   knows which side of the merge commit to consider to be the mainline.

2) Pass it the "-n" command-line option so that the applied change is
   not automatically committed.  This one is needed because the commit
   representing a stash entry has a pre-cooked commit message, and by
   default `git cherry-pick` commits the transferred change using the
   commit message of the change; in this case this is most probably not
   what you want.

So, do

  git cherry-pick -m 1 -n stash@{0}

followed by

  git commit

to get your change intergated.

You received this message because you are subscribed to the Google Groups "Git 
for human beings" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to git-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to