git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Switching branch before commit
@ 2007-05-10 19:43 Ron Parker
  2007-05-10 20:02 ` Adam Roben
  2007-05-10 20:08 ` Junio C Hamano
  0 siblings, 2 replies; 3+ messages in thread
From: Ron Parker @ 2007-05-10 19:43 UTC (permalink / raw)
  To: git

I know this is probably a FAQ and I thought I found it somewhere once,
but... How do I commit changes from in my working directory to another
(possibly non-existent) branch?
 
All too often I am working on changes and realize I am sitting on master
or a topic branch and I need to commit my mods to different branch.  I
really don't like:
 
    git commit
    git branch <other-branch>
    git reset --hard HEAD^
 
Is there anything like:
    git commit -b <other-branch> [<file>...]?

If not, would patches to implement such a change be accepted?

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Switching branch before commit
  2007-05-10 19:43 Switching branch before commit Ron Parker
@ 2007-05-10 20:02 ` Adam Roben
  2007-05-10 20:08 ` Junio C Hamano
  1 sibling, 0 replies; 3+ messages in thread
From: Adam Roben @ 2007-05-10 20:02 UTC (permalink / raw)
  To: Ron Parker; +Cc: git

On May 10, 2007, at 12:43 PM, Ron Parker wrote:

> I know this is probably a FAQ and I thought I found it somewhere once,
> but... How do I commit changes from in my working directory to another
> (possibly non-existent) branch?
>
> All too often I am working on changes and realize I am sitting on  
> master
> or a topic branch and I need to commit my mods to different branch.  I
> really don't like:
>
>    git commit
>    git branch <other-branch>
>    git reset --hard HEAD^
>
> Is there anything like:
>    git commit -b <other-branch> [<file>...]?
>
> If not, would patches to implement such a change be accepted?

    You can do this simply by doing the following:

git checkout -b <other-branch>
git commit

    The changes in your working tree will be carried over to <other- 
branch> when you do the git-checkout command.

-Adam

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Switching branch before commit
  2007-05-10 19:43 Switching branch before commit Ron Parker
  2007-05-10 20:02 ` Adam Roben
@ 2007-05-10 20:08 ` Junio C Hamano
  1 sibling, 0 replies; 3+ messages in thread
From: Junio C Hamano @ 2007-05-10 20:08 UTC (permalink / raw)
  To: Ron Parker; +Cc: git

"Ron Parker" <ron.parker@mobot.org> writes:

> I know this is probably a FAQ and I thought I found it somewhere once,
> but... How do I commit changes from in my working directory to another
> (possibly non-existent) branch?
>  
> All too often I am working on changes and realize I am sitting on master
> or a topic branch and I need to commit my mods to different branch.  I
> really don't like:
>  
>     git commit
>     git branch <other-branch>
>     git reset --hard HEAD^

I do not like that either, and I wouldn't do that.  In fact that
would not work, as "git branch" would not switch to the other
branch you just created.

I would do:

	$ git checkout -b other-branch

which would create and switch to other-branch, based on the
current HEAD (in your case, 'master'), WITHOUT disrupting what
is in your working tree and the index.

and then (perhaps after working on it some more to perfection):

	$ git commit

to commit that work I (mistakenly) started on 'master' in that
other branch.  Then I would come back to master:

	$ git checkout master

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-05-10 20:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-05-10 19:43 Switching branch before commit Ron Parker
2007-05-10 20:02 ` Adam Roben
2007-05-10 20:08 ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).