Re: [BUG] git checkout <branch> allowed with uncommitted changes
- From
- Holger Hellmuth <hellmuth@ira.uka.de>
- Date
- Oct 13, 2011, 16:32 UTC
- Message-ID
- <4E97129C.3090609@ira.uka.de>
- In-Reply-To
- <loom.20111013T171530-970@post.gmane.org>
On 13.10.2011 17:53, arQon wrote:
Show 20 quoted lines
>> git st > # On branch foo > # Changes not staged for commit: > # (use "git add<file>..." to update what will be committed) > # (use "git checkout --<file>..." to discard changes in working directory) > # > # modified: file1.txt > # > no changes added to commit (use "git add" and/or "git commit -a") > > What makes this really interesting though is this: I tried to switch to > master to see if that gave the same warning, and NOW, I get the correct > error. > >> git co master > error: Your local changes to the following files would be overwritten by > checkout: > file1.txt > Please, commit your changes or stash them before you can switch branches. > Aborting
At the end of your example (in a previous email) you were on branch master, now in the beginning you are on foo. So you at least changed branch again inbetween. maybe you also committed something? Check out git log or gitk
I tried your example and I can checkout master and foo again and again and I never see the error message.
Show 7 quoted lines
> Lucky you. :P The most likely reason for me is, I'm working on something > and I get interrupted and have to switch. Since the code may well not even > compile at this point, the last thing I want to do is commit it. git's > ability for that commit to be local is half the reason I'm trying to switch > to it. (I'm not particularly keen on having to commit broken code to even a > local repo, but that's still a hell of a lot better than having it pushed > upstream as well).
As Alexey already said, just commit and later amend. Or stash. Git encourages you to commit small changes you can put a name to. You never should delay a commit because it produces unworkable code. Instead have a master branch (or branches) that always compiles and branches for the unfinished stuff. Then it won't matter if some branch is only half working.