git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: funeeldy <Marlene_Cote@affirmednetworks.com>
Cc: git@vger.kernel.org
Subject: Re: git checkout no longer warning about uncommitted/untracked files!
Date: Mon, 23 May 2011 17:18:26 -0400	[thread overview]
Message-ID: <20110523211826.GD6281@sigill.intra.peff.net> (raw)
In-Reply-To: <1306184704408-6396225.post@n2.nabble.com>

On Mon, May 23, 2011 at 02:05:04PM -0700, funeeldy wrote:

> This is with version 1.7.5.2 - it just keeps the files as modified when I
> checkout a different branch.

Right. This has always been the way git works.

> The bad thing about this is that if I make a change on both branches,
> only the last change is kept, silently.

No, in the example below, you don't actually make a change on a branch.
You make a change to your _worktree_, but that change is not associated
with a branch until you actually commit (which you never do in your
example).

> private/marlene_cote/test/anroot/projects/kernel main_int $ git st
> # On branch main_int
> # Changed but not updated:
> #   (use "git add <file>..." to update what will be committed)
> #   (use "git checkout -- <file>..." to discard changes in working
> directory)
> #
> #	modified:   Makefile
> #
> no changes added to commit (use "git add" and/or "git commit -a")

OK, so you have a change to your Makefile...

> /private/marlene_cote/test/anroot/projects/kernel main_int $ git checkout
> main
> M	Makefile
> Branch main set up to track remote branch main from origin.
> Switched to a new branch 'main'

And now you switch to another branch. Because the version of Makefile in
"main" is the same as the one on "main_int", git can switch branches and
preserve your worktree change (if there had been a change to Makefile in
main_int, you would have seen an error, and git would have told you to
commit or stash your change sfirst).

> /private/marlene_cote/test/anroot/projects/kernel main $ git checkout
> main_int
> M	Makefile
> Switched to branch 'main_int'

Now you're back on main_int, but again, you still have the same change
in Makefile in your worktree.

> /private/marlene_cote/test/anroot/projects/kernel main_int $ git checkout
> main
> M	Makefile
> Switched to branch 'main'

And back to main, with the same change in the worktree.

> v/private/marlene_cote/test/anroot/projects/kernel main $ vi Makefile 

And now you edit the Makefile to new content. If you are expecting the
intermediate state of the Makefile to be kept, it is not. You never
committed it.

> /private/marlene_cote/test/anroot/projects/kernel main $ git checkout
> main_int
> M	Makefile
> Switched to branch 'main_int'

And you still have the new content, because none of these checkouts is
changing your Makefile at all; you are just switching other files around
while the same changes to Makefile sit in the worktree.

-Peff

      parent reply	other threads:[~2011-05-23 21:18 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-23 17:29 git checkout no longer warning about uncommitted/untracked files! funeeldy
2011-05-23 20:37 ` René Scharfe
2011-05-23 21:10   ` Jeff King
2011-05-23 21:05 ` funeeldy
2011-05-23 21:17   ` funeeldy
2011-05-23 21:18     ` Jeff King
2011-05-23 21:27       ` Marlene Cote
2011-05-23 21:18   ` Jeff King [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110523211826.GD6281@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=Marlene_Cote@affirmednetworks.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).