Re: "git checkout" resets modified files

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

 



Steve Heyns <notzippy@xxxxxxxxx> writes:

> "git checkout" resets modified files
>
> Version git  2.5.0,
>
> Description:
> I was automating a process that would pull and switch to another
> branch when I stumbled across this. I have not been able to emulate
> this from command line but using go (or I imagine other languages are
> similar) if you execute a command like
>
> exec.Command("git","checkout","")
>
> A checkout with the branch parameter but the branch parameter is empty.

It is not feeding an empty branch parameter [*1*].  It is asking Git
to check out all paths that match a pathspec "" out of the index.

Now, arguably, the user who would want to match everything may be
more likely to give "." as the pathspec (or if she is not at the
root of the working tree, ":/"), but "" means the same thing as ".",
and the requested behaviour "check out all that match this pathspec
from the index" would essentially mean "I want to get rid of all the
modification in my working tree relative to the index".

I do not think this behaviour depends on the vintage of Git.  An
empty string as pathspec has always matched "everything in here"
AFAIR.


[Footnote]

*1* Checking out a branch whose name is an empty string can be asked
    explicitly by disambiguating double-dash like this:

    $ git checkout "" --

And it will be answered (correctly) with:

    fatal: invalid reference
--
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]