Re: Switching branches without committing changes
- From
Shawn O. Pearce <spearce@spearce.org>
- Date
- Mar 21, 2008, 04:06 UTC
- Message-ID
- <20080321040647.GE8410@spearce.org>
- In-Reply-To
- <A17C3E8C-3D0E-41B4-8A43-37EC8C3F55C2@faithfulgeek.org>
Joe Fiorini <joe@faithfulgeek.org> wrote:
Show 12 quoted lines
> 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.