{"thread":{"id":"50985","subject":"Checkout file without changing index?","startedAt":"2019-04-24T13:37:20Z","lastAt":"2019-04-25T04:04:13Z","messageCount":6,"participants":["Piotr Krukowiecki","Junio C Hamano","Philip Oakley","Sitaram Chamarty"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"374391","messageId":"CAA01CsoJZMJ86mpybukqT0hVnvXi0FuRjZ23akM5kNPBdT754Q@mail.gmail.com","threadId":"50985","inReplyTo":null,"subject":"Checkout file without changing index?","fromName":"Piotr Krukowiecki","fromEmail":"piotr.krukowiecki@gmail.com","sentAt":"2019-04-24T13:37:05Z","receivedAt":"2019-04-24T13:37:20Z","isPatch":false,"sender":{"key":"piotr.krukowiecki@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3259959?v=4"},"body":"Hi,\n\nwhat is the standard/recommended way for updating a file to given version?\n\nI was familiar with \"git checkout revision -- file\".\n\nBut it updates both working tree and index. I had some changes in\nindex (staged) and \"git checkout HEAD -- file\" silently overwritten\nit. Well, probably my mistake, it's documented.\n\nAfter searching a bit I found \"git show revision:file > file\". But\nit's problematic:\n1. works only for 1 file. \"git show revision -- file\" does something else\n2. requires full path, so you need to specify \"git show\nrevision:relative/to/top/dir/file\"\n\nIf there's no other easy way, maybe we could add \"--no-index\" to\ncheckout: \"git checkout --no-index revision -- file\" (or similar -\nmaybe use options from git-reset).\n\nMy use case: I had some changes prepared in index and wanted to\ncompare the prepared version with some older version. The file was a\nzip file plus we use LFS so there was no other way than to \"checkout\"\nthe file, unpack it and diff it.\n\n-- \nPiotr Krukowiecki\n"},{"id":"374393","messageId":"xmqq5zr31poo.fsf@gitster-ct.c.googlers.com","threadId":"50985","inReplyTo":"CAA01CsoJZMJ86mpybukqT0hVnvXi0FuRjZ23akM5kNPBdT754Q@mail.gmail.com","subject":"Re: Checkout file without changing index?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2019-04-24T13:46:31Z","receivedAt":"2019-04-24T13:46:37Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Piotr Krukowiecki <piotr.krukowiecki@gmail.com> writes:\n\n> I was familiar with \"git checkout revision -- file\".\n>\n> But it updates both working tree and index. I had some changes in\n> index (staged) and \"git checkout HEAD -- file\" silently overwritten\n> it. Well, probably my mistake, it's documented.\n\nWe'd invite you to live on the leading edge and try\n\n    $ git restore --source=<revision> <pathspec>\n\nwhich by default checks things out only to the working tree, but not\nto the index (you say --staged if you want to restore to the index,\nand you say --worktree if you want to restore to the working tree,\nor you can say both, which would be the same as \"git checkout\").\n\nI think the new command is now on the 'pu' branch, but in a few\nweeks hopefully it will appear on the 'next' branch.\n"},{"id":"374413","messageId":"CAA01CsrsSQ-_bhS_T5gxDqtPa0XKbHp1c7WCgdxLVvEA3fBSGA@mail.gmail.com","threadId":"50985","inReplyTo":"xmqq5zr31poo.fsf@gitster-ct.c.googlers.com","subject":"Re: Checkout file without changing index?","fromName":"Piotr Krukowiecki","fromEmail":"piotr.krukowiecki@gmail.com","sentAt":"2019-04-24T18:15:37Z","receivedAt":"2019-04-24T18:15:51Z","isPatch":false,"sender":{"key":"piotr.krukowiecki@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3259959?v=4"},"body":"On Wed, Apr 24, 2019 at 3:46 PM Junio C Hamano <gitster@pobox.com> wrote:\n>\n> Piotr Krukowiecki <piotr.krukowiecki@gmail.com> writes:\n>\n> > I was familiar with \"git checkout revision -- file\".\n> >\n> > But it updates both working tree and index. I had some changes in\n> > index (staged) and \"git checkout HEAD -- file\" silently overwritten\n> > it. Well, probably my mistake, it's documented.\n>\n> We'd invite you to live on the leading edge and try\n>\n>     $ git restore --source=<revision> <pathspec>\n>\n> which by default checks things out only to the working tree, but not\n> to the index (you say --staged if you want to restore to the index,\n> and you say --worktree if you want to restore to the working tree,\n> or you can say both, which would be the same as \"git checkout\").\n\nThanks, looks nice. git-checkout is a bit inconsistent at what it\ndoes, and I understand the git-restore and git-switch are a better\nreplacement for it.\n\n\n> I think the new command is now on the 'pu' branch, but in a few\n> weeks hopefully it will appear on the 'next' branch.\n\nIs it possible to get a Windows build?\n\n\n-- \nPiotr Krukowiecki\n"},{"id":"374424","messageId":"2d3fe651-d1b7-5992-f091-fb72ad944d5f@iee.org","threadId":"50985","inReplyTo":"CAA01CsrsSQ-_bhS_T5gxDqtPa0XKbHp1c7WCgdxLVvEA3fBSGA@mail.gmail.com","subject":"Re: Checkout file without changing index?","fromName":"Philip Oakley","fromEmail":"philipoakley@iee.org","sentAt":"2019-04-24T20:16:44Z","receivedAt":"2019-04-24T20:16:47Z","isPatch":false,"sender":{"key":"philipoakley@iee.email","avatar":"https://avatars.githubusercontent.com/u/914343?v=4"},"body":"Hi Piotr\n\nOn 24/04/2019 19:15, Piotr Krukowiecki wrote:\n>> I think the new command is now on the 'pu' branch, but in a few\n>> weeks hopefully it will appear on the 'next' branch.\n> Is it possible to get a Windows build?\nDscho maintains a relatively recent merge with pu at his \nhttps://github.com/git-for-windows/git  shears/pu branch\n\nhttps://public-inbox.org/git/nycvar.QRO.7.76.6.1904051528130.41@tvgsbejvaqbjf.bet/ \nref [1]\n\nPhilip\n\n\n"},{"id":"374451","messageId":"005b0aed-2c20-0c91-e4ad-98b0ec39359d@gmail.com","threadId":"50985","inReplyTo":"xmqq5zr31poo.fsf@gitster-ct.c.googlers.com","subject":"Re: Checkout file without changing index?","fromName":"Sitaram Chamarty","fromEmail":"sitaramc@gmail.com","sentAt":"2019-04-25T03:40:50Z","receivedAt":"2019-04-25T03:40:53Z","isPatch":false,"sender":{"key":"sitaramc@gmail.com","avatar":"https://avatars.githubusercontent.com/u/43316?v=4"},"body":"\n\nOn 24/04/2019 19.16, Junio C Hamano wrote:\n> Piotr Krukowiecki <piotr.krukowiecki@gmail.com> writes:\n> \n>> I was familiar with \"git checkout revision -- file\".\n>>\n>> But it updates both working tree and index. I had some changes in\n>> index (staged) and \"git checkout HEAD -- file\" silently overwritten\n>> it. Well, probably my mistake, it's documented.\n> \n> We'd invite you to live on the leading edge and try\n> \n>     $ git restore --source=<revision> <pathspec>\n> \n> which by default checks things out only to the working tree, but not\n> to the index (you say --staged if you want to restore to the index,\n> and you say --worktree if you want to restore to the working tree,\n> or you can say both, which would be the same as \"git checkout\").\n> \n> I think the new command is now on the 'pu' branch, but in a few\n> weeks hopefully it will appear on the 'next' branch.\n\nI'm not in a position to use either of those on at least some of my\nsystems, but meanwhile, I thought I'd ask this: what is the difference\nbetween this and \"git show REF:PATH > PATH\", in terms of side-effects.\n\n(I.e., any differences other than looking cleaner, not having to repeat\n\"PATH\" etc.)\n\nthanks\nsitaram\n"},{"id":"374452","messageId":"xmqqv9z2ybob.fsf@gitster-ct.c.googlers.com","threadId":"50985","inReplyTo":"005b0aed-2c20-0c91-e4ad-98b0ec39359d@gmail.com","subject":"Re: Checkout file without changing index?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2019-04-25T04:02:44Z","receivedAt":"2019-04-25T04:04:13Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Sitaram Chamarty <sitaramc@gmail.com> writes:\n\n> I'm not in a position to use either of those on at least some of my\n> systems, but meanwhile, I thought I'd ask this: what is the difference\n> between this and \"git show REF:PATH > PATH\", in terms of side-effects.\n>\n> (I.e., any differences other than looking cleaner, not having to repeat\n> \"PATH\" etc.)\n\nFor that matter, what's the difference between these two and\n\n\tgit cat-file --filters REF:PATH >PATH\n\n;-)\n\nI think the major difference is that checkout and restore are facing\nan end-user who is typing the command to the terminal interactively,\nso it does not make it easy to deposit the contents to an arbitrary\npath while taking pathspecs to allow multiple files to be checked\nout.  On the other hand, these \"get content for a single path out of\nthe odb and then write it out to wherever I want to\" may be more\nsuited for scripting.\n\nBetween the two that are for the-content-at-a-single-path, I would\nfurther expect \"git show REF:PATH\" output would be less reliable\nover time, as we reserve the right to add frills to the output from\nthe command to make it a more pleasant experience to humans (e.g. it\nis not totally inconceivable for the command to notice \"ah, this is\na JavaScript source file, so let's pass it through a syntax-aware\nhighligher), as opposed to placing more emphasis on the byte for\nbyte fidelity, which is desired for components used in scripts.\nThose who would want the latter should be using the plumbing\ncat-file.\n"}]}