{"thread":{"id":"56356","subject":"git read-tree doesn't accept tree-ish","startedAt":"2021-08-23T17:30:45Z","lastAt":"2021-08-23T19:38:03Z","messageCount":7,"participants":["Nikita Bobko","Elijah Newren","Jeff King","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"433466","messageId":"CAMJzOtxMjEuAy2B3oJqOZEnipmC4OBWxhQLx_baXDHcQ1C7-+g@mail.gmail.com","threadId":"56356","inReplyTo":null,"subject":"git read-tree doesn't accept tree-ish","fromName":"Nikita Bobko","fromEmail":"nikitabobko@gmail.com","sentAt":"2021-08-23T17:31:29Z","receivedAt":"2021-08-23T17:30:45Z","isPatch":false,"sender":{"key":"nikitabobko@gmail.com","avatar":null},"body":"```\ngit init\necho foo > foo\ngit add --all\ngit commit -m 'foo'\n\necho bar > foo\ngit add --all\ngit commit -m 'bar'\n\ngit read-tree HEAD~:foo\n```\nEXP: Read information about file `foo` into index\nACT: `fatal: failed to unpack tree object HEAD~:foo`\n\nI expect it to work because manpage says that `git-read-tree` accepts\n`<tree-ish>`\n"},{"id":"433468","messageId":"CABPp-BE7JMdWi5DzHkkkZiM-7u1pW3uhwh1W69yEOxaGuAmUbw@mail.gmail.com","threadId":"56356","inReplyTo":"CAMJzOtxMjEuAy2B3oJqOZEnipmC4OBWxhQLx_baXDHcQ1C7-+g@mail.gmail.com","subject":"Re: git read-tree doesn't accept tree-ish","fromName":"Elijah Newren","fromEmail":"newren@gmail.com","sentAt":"2021-08-23T17:38:09Z","receivedAt":"2021-08-23T17:38:24Z","isPatch":false,"sender":{"key":"newren@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5455730?v=4"},"body":"On Mon, Aug 23, 2021 at 10:32 AM Nikita Bobko <nikitabobko@gmail.com> wrote:\n>\n> ```\n> git init\n> echo foo > foo\n> git add --all\n> git commit -m 'foo'\n>\n> echo bar > foo\n> git add --all\n> git commit -m 'bar'\n>\n> git read-tree HEAD~:foo\n> ```\n> EXP: Read information about file `foo` into index\n> ACT: `fatal: failed to unpack tree object HEAD~:foo`\n>\n> I expect it to work because manpage says that `git-read-tree` accepts\n> `<tree-ish>`\n\nHEAD~:foo is not a tree in your example, it's a blob.  Try running\nthis: `git cat-file -t HEAD~:foo`, to see the type.\n"},{"id":"433480","messageId":"YSPuq/HmF3tnYHCA@coredump.intra.peff.net","threadId":"56356","inReplyTo":"CAMJzOtxMjEuAy2B3oJqOZEnipmC4OBWxhQLx_baXDHcQ1C7-+g@mail.gmail.com","subject":"Re: git read-tree doesn't accept tree-ish","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2021-08-23T18:53:31Z","receivedAt":"2021-08-23T18:53:34Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Aug 23, 2021 at 07:31:29PM +0200, Nikita Bobko wrote:\n\n> ```\n> git init\n> echo foo > foo\n> git add --all\n> git commit -m 'foo'\n> \n> echo bar > foo\n> git add --all\n> git commit -m 'bar'\n> \n> git read-tree HEAD~:foo\n> ```\n> EXP: Read information about file `foo` into index\n> ACT: `fatal: failed to unpack tree object HEAD~:foo`\n> \n> I expect it to work because manpage says that `git-read-tree` accepts\n> `<tree-ish>`\n\nIn your example, \"foo\" is a blob, not a tree. And thus HEAD~:foo\nis not a tree-ish. Just \"HEAD~\" would be.\n\nWhat are you trying to do?\n\n-Peff\n"},{"id":"433481","messageId":"CAMJzOtz_h0iEL1VQCFvvLzw3XnL+qM=f+BvkmsTU=ps+0VA7RA@mail.gmail.com","threadId":"56356","inReplyTo":"YSPuq/HmF3tnYHCA@coredump.intra.peff.net","subject":"Re: git read-tree doesn't accept tree-ish","fromName":"Nikita Bobko","fromEmail":"nikitabobko@gmail.com","sentAt":"2021-08-23T19:10:33Z","receivedAt":"2021-08-23T19:09:49Z","isPatch":false,"sender":{"key":"nikitabobko@gmail.com","avatar":null},"body":"Yes, now I see. Thanks!\n\nI was trying to read state of a particular directory/file from a\nparticular revision into my index but so far didn't manage to do it\nreliably.\n\nI was using `git read-tree <hash>:<path>` and it doesn't work for\nfiles (because they are blobs not tree-ish as you elaborated it to me)\nand for directories, in my cases, it fails with not so helpful\nmessage:\n```\nerror: Entry '<path>/<subpath>' overlaps with '<path>/<subpath>'.  Cannot bind.\n```\n\n`git checkout <hash> -- <path>` also doesn't work in my case because\nif any file is removed in `<hash>` but not in my HEAD then `git\ncheckout` doesn't remove the file in my HEAD\n\nOn Mon, Aug 23, 2021 at 8:53 PM Jeff King <peff@peff.net> wrote:\n>\n> On Mon, Aug 23, 2021 at 07:31:29PM +0200, Nikita Bobko wrote:\n>\n> > ```\n> > git init\n> > echo foo > foo\n> > git add --all\n> > git commit -m 'foo'\n> >\n> > echo bar > foo\n> > git add --all\n> > git commit -m 'bar'\n> >\n> > git read-tree HEAD~:foo\n> > ```\n> > EXP: Read information about file `foo` into index\n> > ACT: `fatal: failed to unpack tree object HEAD~:foo`\n> >\n> > I expect it to work because manpage says that `git-read-tree` accepts\n> > `<tree-ish>`\n>\n> In your example, \"foo\" is a blob, not a tree. And thus HEAD~:foo\n> is not a tree-ish. Just \"HEAD~\" would be.\n>\n> What are you trying to do?\n>\n> -Peff\n"},{"id":"433482","messageId":"CABPp-BHibnrJYAYe-uX_ib7DFR5kkd=G2Jh+nhANPkfbnoFOzw@mail.gmail.com","threadId":"56356","inReplyTo":"CAMJzOtz_h0iEL1VQCFvvLzw3XnL+qM=f+BvkmsTU=ps+0VA7RA@mail.gmail.com","subject":"Re: git read-tree doesn't accept tree-ish","fromName":"Elijah Newren","fromEmail":"newren@gmail.com","sentAt":"2021-08-23T19:23:23Z","receivedAt":"2021-08-23T19:23:37Z","isPatch":false,"sender":{"key":"newren@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5455730?v=4"},"body":"Hi,\n\nOn Mon, Aug 23, 2021 at 12:09 PM Nikita Bobko <nikitabobko@gmail.com> wrote:\n>\n> Yes, now I see. Thanks!\n>\n> I was trying to read state of a particular directory/file from a\n> particular revision into my index but so far didn't manage to do it\n> reliably.\n\nPlease don't top-post on this list.\n\n> I was using `git read-tree <hash>:<path>` and it doesn't work for\n> files (because they are blobs not tree-ish as you elaborated it to me)\n> and for directories, in my cases, it fails with not so helpful\n> message:\n> ```\n> error: Entry '<path>/<subpath>' overlaps with '<path>/<subpath>'.  Cannot bind.\n> ```\n>\n> `git checkout <hash> -- <path>` also doesn't work in my case because\n> if any file is removed in `<hash>` but not in my HEAD then `git\n> checkout` doesn't remove the file in my HEAD\n\nHave you tried `git restore --source=<hash> -- <path>` ?\n"},{"id":"433483","messageId":"xmqq5yvwq7w5.fsf@gitster.g","threadId":"56356","inReplyTo":"CAMJzOtz_h0iEL1VQCFvvLzw3XnL+qM=f+BvkmsTU=ps+0VA7RA@mail.gmail.com","subject":"Re: git read-tree doesn't accept tree-ish","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2021-08-23T19:27:06Z","receivedAt":"2021-08-23T19:27:11Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Nikita Bobko <nikitabobko@gmail.com> writes:\n\n> `git checkout <hash> -- <path>` also doesn't work in my case because\n> if any file is removed in `<hash>` but not in my HEAD then `git\n> checkout` doesn't remove the file in my HEAD\n\nLook for \"--no-overlay\" option in \"git checkout\", perhaps?\n"},{"id":"433485","messageId":"CAMJzOtwwxKz3_cgpOOOx-tYE-qHUyMWfXu+dKEBHhz2Aov4MyQ@mail.gmail.com","threadId":"56356","inReplyTo":"xmqq5yvwq7w5.fsf@gitster.g","subject":"Re: git read-tree doesn't accept tree-ish","fromName":"Nikita Bobko","fromEmail":"nikitabobko@gmail.com","sentAt":"2021-08-23T19:38:40Z","receivedAt":"2021-08-23T19:38:03Z","isPatch":false,"sender":{"key":"nikitabobko@gmail.com","avatar":null},"body":"> Have you tried `git restore --source=<hash> -- <path>` ?\n\nAt a glance, it looks what I am looking for\n\n> Look for \"--no-overlay\" option in \"git checkout\", perhaps?\n\nOh, and it works too. So many ways to do almost exactly the same thing...\n\nAnyway, thanks everyone for the help! My issue may be considered as\nresolved. Now I will dig into manpages and experiments to see which of\nthe suggested variants suits me best\n\nOn Mon, Aug 23, 2021 at 9:27 PM Junio C Hamano <gitster@pobox.com> wrote:\n>\n> Nikita Bobko <nikitabobko@gmail.com> writes:\n>\n> > `git checkout <hash> -- <path>` also doesn't work in my case because\n> > if any file is removed in `<hash>` but not in my HEAD then `git\n> > checkout` doesn't remove the file in my HEAD\n>\n> Look for \"--no-overlay\" option in \"git checkout\", perhaps?\n"}]}