Re: git checkout no longer warning about uncommitted/untracked files!

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

 



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
--
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]