Re: [BUG] git checkout <branch> allowed with uncommitted changes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 13.10.2011 17:53, arQon wrote:
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.

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.

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]