* You have local changes; cannot switch branches error question
@ 2009-12-24 22:25 Eugene Sajine
2009-12-24 22:59 ` Nanako Shiraishi
2009-12-24 23:32 ` Junio C Hamano
0 siblings, 2 replies; 4+ messages in thread
From: Eugene Sajine @ 2009-12-24 22:25 UTC (permalink / raw
To: git; +Cc: Eugene Sajine
First of all Merry Christmas and Happy New Year to everybody! I wish
Git to move to global dominance during next year even faster then it
does now;)
My question is related to the fact that most of the time when i have
some local file changes Git is switching branches OK. But from time to
time in some repos I'm hitting this error and I cannot figure out why
it suddenly starts to complain about it?
For example in one of my repos I somehow got to a state when I have
three files modified, and when I'm trying to switch branches it
complains about one of them being changed locally, so it refuses to
switch branch
OTOH i have tried many different scenarios in another repo to leave
some uncommitted staged or not staged changes and switch branches and
same version of git does that just fine. (v 1.6.5.6).
So, what is correct behavior - do not switch or switch branches when
there are uncommitted changes?
Thanks,
Eugene
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: You have local changes; cannot switch branches error question
2009-12-24 22:25 You have local changes; cannot switch branches error question Eugene Sajine
@ 2009-12-24 22:59 ` Nanako Shiraishi
2009-12-24 23:32 ` Junio C Hamano
1 sibling, 0 replies; 4+ messages in thread
From: Nanako Shiraishi @ 2009-12-24 22:59 UTC (permalink / raw
To: Eugene Sajine; +Cc: git
Quoting Eugene Sajine <euguess@gmail.com>
> My question is related to the fact that most of the time when i have
> some local file changes Git is switching branches OK. But from time to
> time in some repos I'm hitting this error and I cannot figure out why
> it suddenly starts to complain about it?
The command is telling you that it refrained to overwrite
your local changes. It's not complaining. There is an
excellent summary of what switching branches with 'git
checkout' while you have local changes in your working tree.
http://thread.gmane.org/gmane.comp.version-control.git/77700/focus=77708
--
Nanako Shiraishi
http://ivory.ap.teacup.com/nanako3/
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: You have local changes; cannot switch branches error question
2009-12-24 22:25 You have local changes; cannot switch branches error question Eugene Sajine
2009-12-24 22:59 ` Nanako Shiraishi
@ 2009-12-24 23:32 ` Junio C Hamano
2009-12-25 14:32 ` Matthieu Moy
1 sibling, 1 reply; 4+ messages in thread
From: Junio C Hamano @ 2009-12-24 23:32 UTC (permalink / raw
To: Eugene Sajine; +Cc: git
Eugene Sajine <euguess@gmail.com> writes:
> For example in one of my repos I somehow got to a state when I have
> three files modified, and when I'm trying to switch branches it
> complains about one of them being changed locally, so it refuses to
> switch branch
Suppose you have a history like this:
o---B side
/
---o----o----A master
and both branches 'master' and 'side' have file, F and G. G is different
between commits A and B while F is the same between these two commits.
You have 'master' checked out, and modified both F and G. This table
shows the contents you have in each path:
path master work tree side
-----------------------------------------
F F1 F2 F1
G G1 G2 G3
In git, your local modification does _not_ belong to any branch. You need
to commit them if you want to make them part of the history of your
current branch. Checking out a different branch means you switch to the
branch and carry these changes along with you. But it is not necessarily
be possible to do so without modifying what is in your work tree.
For path F, your local change is (F2-F1), and switching to branch 'side'
means you would transplant that change on top of what that branch has,
which happens to be F1. That means the result is F2 (= F1 + (F2-F1)).
IOW, because F is identical between master and side, the file in your work
tree can stay the same.
Now, think what should happen to path G. The local change is (G2-G1), and
you need to transplant that change on top of G3, that is different from
G1. This computation will involve a merge, which you may or may not be
prepared to resolve.
If you are used to CVS/SVN workflow where you "update" to merge other's
changes to your work tree with your own local changes, you will know that
with such a merge, depending on the amount of change between G1 and G3,
you may end up losing quite a lot of work of your own (G2-G1), when the
merge is too complicated for you to handle. The message you saw is a
safety valve to prevent you from trashing your work that way.
There are two ways to deal with this situation, one safely, and another
quickly.
- You can "stash save" to first save the changes in your work tree,
"checkout" to switch to branch 'side', and then "stash pop" to attempt
the merge.
The last step of unstashing on the new branch _will_ give you the same
kind of conflict while computing G3 + (G2 - G1) to update file G, but
the approach has one huge advantage compared to CVS/SVN's "update", in
that you can "reset --hard" and "stash pop" to reset to a clean state
and attempt resolution if you failed resolve conflicts and end up
making a mess in your first try.
- If you _know_ that the changes between G1 and G3 do not conflict with
what you did between G1 and G2, you can "checkout -m" to instruct it to
act as if it were CVS/SVN's "update" command.
This can potentially make an unresolvable mess in your work tree, and
you can end up losing your changes G2-G1, but it is quicker than "stash
save"/"stash pop" pair.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: You have local changes; cannot switch branches error question
2009-12-24 23:32 ` Junio C Hamano
@ 2009-12-25 14:32 ` Matthieu Moy
0 siblings, 0 replies; 4+ messages in thread
From: Matthieu Moy @ 2009-12-25 14:32 UTC (permalink / raw
To: Junio C Hamano; +Cc: Eugene Sajine, git
Junio C Hamano <gitster@pobox.com> writes:
> There are two ways to deal with this situation, one safely, and another
> quickly.
And a third one : commit, and then rebase onto the other branch. It's
safe, and nice when your local changes are ready to commit (then, you
can write the commit message before bothering about potential merge
conflicts).
--
Matthieu Moy
http://www-verimag.imag.fr/~moy/
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2009-12-25 14:32 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-12-24 22:25 You have local changes; cannot switch branches error question Eugene Sajine
2009-12-24 22:59 ` Nanako Shiraishi
2009-12-24 23:32 ` Junio C Hamano
2009-12-25 14:32 ` Matthieu Moy
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).