git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Shawn O. Pearce" <spearce@spearce.org>
To: Joe Fiorini <joe@faithfulgeek.org>
Cc: git@vger.kernel.org
Subject: Re: Switching branches without committing changes
Date: Fri, 21 Mar 2008 00:06:47 -0400	[thread overview]
Message-ID: <20080321040647.GE8410@spearce.org> (raw)
In-Reply-To: <A17C3E8C-3D0E-41B4-8A43-37EC8C3F55C2@faithfulgeek.org>

Joe Fiorini <joe@faithfulgeek.org> wrote:
> I'm still a newbie to Git (and this list), so if I don't provide  
> enough details please let me know what you need and I will provide :).
> 
> I'm trying to switch branches without committing my changes.  Is this  
> possible?  For example, I'm working on a site, I'm testing the  
> implementation of a new technology (branch B), I'm not quite done  
> there (or I forget to commit everything) and I want to implement  
> something else new.  I create a new branch off of B, called B.1, and  
> then make some changes.  I commit only the changes that apply to B.1  
> and then try to go back to B.  However, I get an error saying a file I  
> changed in B is not uptodate and it cannot merge.  What am I doing  
> wrong and how can I get back to B?

Use `git checkout -m` to switch the branch anyway.  However, if
there is a merge conflict while you are trying to carry the changes
to the other branch you may be faced with a merge conflict you are
not prepared to resolve, or simply cannot resolve in a reasonable
period of time.

You may want to use `git stash` to save your dirty changes off to
a safe area, then switch branches.  Your changes won't be there,
but you can get them back with `git stash apply 0`.  If things go
badly, you can go back to B.1 and use `git stash apply 0` to put
the changes back where they were, and figure out what you are going
to do from there.

-- 
Shawn.

  parent reply	other threads:[~2008-03-21  4:07 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-21  3:27 Switching branches without committing changes Joe Fiorini
2008-03-21  3:52 ` Jeff King
2008-03-21  4:06 ` Shawn O. Pearce [this message]
2008-03-21  4:10   ` Jeff King
2008-03-21  4:40     ` Joe Fiorini
2008-03-21  4:42     ` Junio C Hamano
2008-03-21  4:58       ` Joe Fiorini
2008-03-23  1:00       ` Xavier Maillard
2008-03-24 14:46         ` Joe Fiorini
2008-03-24 19:07           ` Jeff King

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=20080321040647.GE8410@spearce.org \
    --to=spearce@spearce.org \
    --cc=git@vger.kernel.org \
    --cc=joe@faithfulgeek.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).