git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [BUG] git checkout <branch> allowed with uncommitted changes
@ 2011-10-13  8:40 arQon
  2011-10-13 10:48 ` Nguyen Thai Ngoc Duy
  2011-10-13 15:09 ` Michael J Gruber
  0 siblings, 2 replies; 36+ messages in thread
From: arQon @ 2011-10-13  8:40 UTC (permalink / raw)
  To: git

Which, as you'd expect, results in both the on-disk copies and other branches
becoming corrupted.

Tested on git versions 1.7.6 and 1.7.7 (msysgit)

http://benno.id.au/blog/2011/10/01/git-recursive-merge-broken describes
something that sounds similar, but that's supposedly fixed on 1.7.7,
whereas this happens on that as well.

master is a tracking branch, "ttfcon" is the branch I was using to develop
a change. Got to a good point on the branch, merged it in:

$ git co master
$ git merge ttfcon
Updating b9f0c75..6280b7a
Fast-forward
 .gitignore                |    2 ++
 code/renderer/tr_font.cpp |   27 ++++++++-------------------
 2 files changed, 10 insertions(+), 19 deletions(-)

$ git st
# On branch master
# Your branch is ahead of 'origin/master' by 3 commits.

back to the branch to mess around with a couple of things to be sure this
is what i want to push
$ git co ttfcon
do stuff

$ git st
# On branch ttfcon
# 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:   code/freetype-2.3.11/builds/win32/visualc/freetype.vcproj
#       modified:   code/renderer/tr_font.cpp

so far so good...

$ git ci -m "blah" code/freetype-2.3.11/builds/win32/visualc/freetype.vcproj
 1 files changed, 4 insertions(+), 0 deletions(-)

note that tr_font is locally modified and still *not committed* at this point.

$ git co master
M       code/renderer/tr_font.cpp
Switched to branch 'master'
Your branch is ahead of 'origin/master' by 3 commits.

boom. instead of rejecting the branch change, git switches branches anyway,
and doesn't do anything about the uncommitted changes in the file itself -
meaning they're now effectively "in" master because they're still on disk,
so now the master is poisoned.

"git st" does show the change:

# On branch master
# Changes not staged for commit:
#       modified:   code/renderer/tr_font.cpp

but it's a change I never MADE on this branch (ie master), only on the
other branch.

"git diff" is just as confused as I am:

$ git diff ttfcon
--- a/code/renderer/tr_font.cpp
+++ b/code/renderer/tr_font.cpp
+		// git branch bug

So it's picking up the difference between the two branches, but as far as
the *actual file* goes, master now has a line in it that shouldn't be there.

I'm just trying out git as a possible replacement for SVN, so maybe I'm
mistaken about what "should" happen, but AIUI git switching branches with
uncommitted changes is a bug (and given that it poisoned a branch that I
wasn't on, it certainly looks like one). A couple of days ago it DID complain
when I tried to switch with uncommitted files still present, so it was working
properly then. I have no idea what's made it happy to ignore them now:
nothing's changed that I know of.

At this point, reverting the master with "checkout --" also wipes out the
changes on the other branch. It's like the merge symlinked the two branches
rather than, well, merging them.

If this is user error, and merge is supposed to break the tree like that,
then sorry for wasting your time, but I can't find anything in the docs that
says (or even suggests) that it should, so...

Thanks.

^ permalink raw reply	[flat|nested] 36+ messages in thread

end of thread, other threads:[~2011-10-16 22:05 UTC | newest]

Thread overview: 36+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-10-13  8:40 [BUG] git checkout <branch> allowed with uncommitted changes arQon
2011-10-13 10:48 ` Nguyen Thai Ngoc Duy
2011-10-13 10:59   ` Alexey Shumkin
2011-10-13 11:51     ` arQon
2011-10-13 12:22       ` Andreas Ericsson
2011-10-13 13:09         ` arQon
2011-10-13 13:59           ` Carlos Martín Nieto
2011-10-13 17:09             ` [CLOSED] " arQon
2011-10-13 18:56               ` Alexey Shumkin
2011-10-13 19:01               ` Jakub Narebski
2011-10-13 13:58         ` [BUG] " arQon
2011-10-13 14:46           ` Carlos Martín Nieto
2011-10-13 15:53             ` arQon
2011-10-13 16:17               ` Alexey Shumkin
2011-10-14  6:51                 ` Alexey Shumkin
2011-10-13 16:32               ` Holger Hellmuth
2011-10-13 17:04               ` Carlos Martín Nieto
2011-10-13 18:19                 ` arQon
2011-10-13 18:28                   ` Junio C Hamano
2011-10-13 18:56                     ` arQon
2011-10-14  1:38                       ` Jeff King
2011-10-14  9:27                         ` Holger Hellmuth
2011-10-14  9:54                           ` Victor Engmark
2011-10-16 18:25                             ` arQon
2011-10-16 20:37                               ` Junio C Hamano
2011-10-16 22:04                                 ` Holger Hellmuth
2011-10-13 20:07                   ` Carlos Martín Nieto
2011-10-13 17:06               ` Sergei Organov
2011-10-13 19:44               ` PJ Weisberg
2011-10-13 16:08           ` Holger Hellmuth
2011-10-13 12:42       ` arQon
2011-10-13 12:55         ` Holger Hellmuth
2011-10-13 14:44         ` Victor Engmark
2011-10-13 16:17           ` arQon
2011-10-14  7:16             ` Victor Engmark
2011-10-13 15:09 ` Michael J Gruber

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).