Re: Switching branch before commit

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



"Ron Parker" <ron.parker@xxxxxxxxx> 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

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux