From: Junio C Hamano <junkio@cox.net>
To: "Ron Parker" <ron.parker@mobot.org>
Cc: <git@vger.kernel.org>
Subject: Re: Switching branch before commit
Date: Thu, 10 May 2007 13:08:44 -0700 [thread overview]
Message-ID: <7v3b24jvar.fsf@assigned-by-dhcp.cox.net> (raw)
In-Reply-To: <769697AE3E25EF4FBC0763CD91AB1B0201D496E7@MBGMail01.mobot.org> (Ron Parker's message of "Thu, 10 May 2007 14:43:23 -0500")
"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
prev parent reply other threads:[~2007-05-10 20:08 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
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 message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7v3b24jvar.fsf@assigned-by-dhcp.cox.net \
--to=junkio@cox.net \
--cc=git@vger.kernel.org \
--cc=ron.parker@mobot.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).