threads / discuss / 23955

Commit to other branch

Subject: Commit to other branch

## tl;dr

4 messages between May 31, 2010 and Jun 6, 2010.

replies: 3people: 4as markdown or json

Johannes Schneider· May 31, 2010, 15:46 UTC · lore
Hi guys,

I often run in that scenario: I see a small bugfix/typo/missing documentation. Of course I just add a bit of code to fix that issue... Then I'd like to commit that change as own commit. And most of the time this is possible without any problems (git commit <file>). But as I am *always* working on a topic branch, it takes some work to commit that change to another branch.

I tried to "git stash " But then *all* changes are stashed (including my changes)...

So at the moment I do that:

git commit <file> (on wrong branch) git stash git checkout pu git cherry-pick git checkout my-topic git reset --hard git stash apply

And that is much to much work. I just want to do something like that:
git commit <file> -b pu

But I don't think that is possible at the moment... Any hints, how I could solve that? How do you do that?

Thanks,
Johannes
-- 
Johannes Schneider - blog.cedarsoft.com
Matthieu Moy· May 31, 2010, 16:28 UTC · re: Johannes Schneider · lore

Re: Commit to other branch

Johannes Schneider <mailings@cedarsoft.com> writes:
> I tried to "git stash "
> But then *all* changes are stashed (including my changes)...

Not completely answering the question, but "git stash -k" (--keep-index) allows you to do a selective stash. If you have relevant changes staged, and want to commit the unstaged ones elsewhere, you can do something like

git stash -k git checkout elsewhere git commit git checkout back-to-your-branch git stash pop

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/
Jeff King· May 31, 2010, 23:50 UTC · re: Matthieu Moy · lore

Re: Commit to other branch

On Mon, May 31, 2010 at 06:28:48PM +0200, Matthieu Moy wrote:
Show 7 quoted lines
> Johannes Schneider <mailings@cedarsoft.com> writes:
> 
> > I tried to "git stash "
> > But then *all* changes are stashed (including my changes)...
> 
> Not completely answering the question, but "git stash -k"
> (--keep-index) allows you to do a selective stash. If you have

Also, recent versions of git have "git stash -p" to interactively stash just a few changes.

-Peff
Jan Hudec· Jun 6, 2010, 18:43 UTC · re: Johannes Schneider · lore

Re: Commit to other branch

On Mon, May 31, 2010 at 17:46:09 +0200, Johannes Schneider wrote:
Show 7 quoted lines
> I often run in that scenario:
> I see a small bugfix/typo/missing documentation. Of course I just add a
> bit of code to fix that issue...
> Then I'd like to commit that change as own commit. And most of the time
> this is possible without any problems (git commit <file>).
> But as I am *always* working on a topic branch, it takes some work to
> commit that change to another branch.

What I'd probably do is just commit the quick fix, as separate commit, where I am. Than when I'd have a bit of time (probably when I'd otherwise think of rebasing on master anyway) I'd rebase -i all such fixes to the bottom of the topic branch, go to master and merge just those fixes. The rebase -i can be against current master, so the merge back would be fast-forward, of course.

-- 
						 Jan 'Bulb' Hudec <bulb@ucw.cz>

← back to recent threads