{"thread":{"id":"25423","subject":"Can I checkout a single file without altering index?","startedAt":"2010-10-12T10:03:17Z","lastAt":"2010-10-15T23:40:08Z","messageCount":16,"participants":["Christian Halstrick","Michael J Gruber","Stefan Naewe","Alex Riesen","Tomas Carnecky","Jared Hance","Neal Kreitzinger","Jonathan Nieder","Jeff King","Andreas Schwab","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"153295","messageId":"loom.20101012T114900-532@post.gmane.org","threadId":"25423","inReplyTo":null,"subject":"Can I checkout a single file without altering index?","fromName":"Christian Halstrick","fromEmail":"christian.halstrick@gmail.com","sentAt":"2010-10-12T10:03:17Z","receivedAt":"2010-10-12T10:03:17Z","isPatch":false,"sender":{"key":"christian.halstrick@gmail.com","avatar":"https://gravatar.com/avatar/3598bf518644c7dc32d4dcd8e0554b6a313e12103011862402c83ae2854203ce?d=mp&s=160"},"body":"Can I checkout a certain file to a specific revision without also adding this \ncontent to the index? I only want to alter the working-tree - no modification of \nindex or HEAD needed.\n\nHere is why I need that: I see a bug in git controlled sources. I fix one source\nfile and also add one unit test in a separate file. I checked that the test\nsucceeds with my fix. The index now contains what I want to commit.\nNow I want to see whether my test fails without my fix. I want to checkout HEAD\nfor the source file without destroying my index. In the end, after I saw that my\ntest fails without my fix, I just want to say \"git commit\" without having to.\n"},{"id":"153296","messageId":"4CB43640.2010402@drmicha.warpmail.net","threadId":"25423","inReplyTo":"loom.20101012T114900-532@post.gmane.org","subject":"Re: Can I checkout a single file without altering index?","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2010-10-12T10:19:44Z","receivedAt":"2010-10-12T10:19:44Z","isPatch":false,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"Christian Halstrick venit, vidit, dixit 12.10.2010 12:03:\n> Can I checkout a certain file to a specific revision without also adding this \n> content to the index? I only want to alter the working-tree - no modification of \n> index or HEAD needed.\n> \n> Here is why I need that: I see a bug in git controlled sources. I fix one source\n> file and also add one unit test in a separate file. I checked that the test\n> succeeds with my fix. The index now contains what I want to commit.\n> Now I want to see whether my test fails without my fix. I want to checkout HEAD\n> for the source file without destroying my index. In the end, after I saw that my\n> test fails without my fix, I just want to say \"git commit\" without having to.\n> \n\nI would recommend to work on top of a trial commit, i.e.\n\ngit commit -m TheFix\ngit checkout HEAD^ -- fixedfile.c\ngit reset --hard\n\nand git commit --amend if needed. (Alternatively, use stash.)\n\nYou can also use\n\ngit show HEAD:fixedfile.c > fixedfile.c\ngit checkout fixed.file.c\ngit commit -m TheFix\n\nbut I find this more cumbersome.\n\nMichael\n"},{"id":"153297","messageId":"4CB44318.7000305@atlas-elektronik.com","threadId":"25423","inReplyTo":"loom.20101012T114900-532@post.gmane.org","subject":"Re: Can I checkout a single file without altering index?","fromName":"Stefan Naewe","fromEmail":"stefan.naewe@atlas-elektronik.com","sentAt":"2010-10-12T11:14:32Z","receivedAt":"2010-10-12T11:14:32Z","isPatch":false,"sender":{"key":"stefan.naewe@gmail.com","avatar":"https://avatars.githubusercontent.com/u/4468?v=4"},"body":"On 10/12/2010 12:03 PM, Christian Halstrick wrote:\n> Can I checkout a certain file to a specific revision without also adding this \n> content to the index? I only want to alter the working-tree - no modification of \n> index or HEAD needed.\n> \n> Here is why I need that: I see a bug in git controlled sources. I fix one source\n> file and also add one unit test in a separate file. I checked that the test\n> succeeds with my fix. The index now contains what I want to commit.\n> Now I want to see whether my test fails without my fix. I want to checkout HEAD\n> for the source file without destroying my index. In the end, after I saw that my\n> test fails without my fix, I just want to say \"git commit\" without having to.\n\ncommit the unit test first, and the fix as a second commit ?\n\nRegards,\n  Stefan\n-- \n----------------------------------------------------------------\n/dev/random says: Help endangered species - adopt a KGB operative.\n"},{"id":"153324","messageId":"AANLkTinnYEnCwpTh45N69n73JQm=ndXH-SUJ5b1piUYv@mail.gmail.com","threadId":"25423","inReplyTo":"loom.20101012T114900-532@post.gmane.org","subject":"Re: Can I checkout a single file without altering index?","fromName":"Alex Riesen","fromEmail":"raa.lkml@gmail.com","sentAt":"2010-10-12T15:39:45Z","receivedAt":"2010-10-12T15:39:45Z","isPatch":false,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"On Tue, Oct 12, 2010 at 12:03, Christian Halstrick\n<christian.halstrick@gmail.com> wrote:\n> Can I checkout a certain file to a specific revision without also adding this\n> content to the index? I only want to alter the working-tree - no modification of\n> index or HEAD needed.\n\n\"git show <revision-specification>:path/name > path/name\" ?\n"},{"id":"153331","messageId":"4CB48F56.3020404@dbservice.com","threadId":"25423","inReplyTo":"AANLkTinnYEnCwpTh45N69n73JQm=ndXH-SUJ5b1piUYv@mail.gmail.com","subject":"Re: Can I checkout a single file without altering index?","fromName":"Tomas Carnecky","fromEmail":"tom@dbservice.com","sentAt":"2010-10-12T16:39:50Z","receivedAt":"2010-10-12T16:39:50Z","isPatch":false,"sender":{"key":"tom@dbservice.com","avatar":"https://gravatar.com/avatar/900a300bdd1a8bbe086008ad78210bbee2ad2803b7d50a5cba04c1e9404bd6d2?d=mp&s=160"},"body":"On 10/12/10 5:39 PM, Alex Riesen wrote:\n> On Tue, Oct 12, 2010 at 12:03, Christian Halstrick\n> <christian.halstrick@gmail.com> wrote:\n>> Can I checkout a certain file to a specific revision without also adding this\n>> content to the index? I only want to alter the working-tree - no modification of\n>> index or HEAD needed.\n> \n> \"git show <revision-specification>:path/name > path/name\" ?\n\nI heard that git-show doesn't apply filters to the file (smudge/clean or\nany custom ones). Keep that in mind when using it.\n\ntom\n"},{"id":"153411","messageId":"loom.20101013T190544-893@post.gmane.org","threadId":"25423","inReplyTo":"4CB44318.7000305@atlas-elektronik.com","subject":"Re: Can I checkout a single file without altering index?","fromName":"Jared Hance","fromEmail":"jaredhance@gmail.com","sentAt":"2010-10-13T17:09:07Z","receivedAt":"2010-10-13T17:09:07Z","isPatch":false,"sender":{"key":"jaredhance@gmail.com","avatar":"https://avatars.githubusercontent.com/u/170192?v=4"},"body":"Stefan Naewe <stefan.naewe <at> atlas-elektronik.com> writes:\n\n> \n> On 10/12/2010 12:03 PM, Christian Halstrick wrote:\n> > Can I checkout a certain file to a specific revision without also adding \nthis \n> > content to the index? I only want to alter the working-tree - no \nmodification of \n> > index or HEAD needed.\n> > \n> > Here is why I need that: I see a bug in git controlled sources. I fix one \nsource\n> > file and also add one unit test in a separate file. I checked that the test\n> > succeeds with my fix. The index now contains what I want to commit.\n> > Now I want to see whether my test fails without my fix. I want to checkout \nHEAD\n> > for the source file without destroying my index. In the end, after I saw \nthat my\n> > test fails without my fix, I just want to say \"git commit\" without having \nto.\n> \n> commit the unit test first, and the fix as a second commit ?\n> \n> Regards,\n>   Stefan\n\nJust to add to this, since you might not want the test and the fix in separate \ncommmits: (as is implied in the message)\n  1. commit unit test.\n  2. commit fix.\n  3. go to detchatched head at HEAD^\n  4. run unit test to insure that it fails.\n  5. checkout the branch again to where you have the fix.\n  6. run unit test to insure that it doesn't fail.\n  7. run `git rebase HEAD^` and merge squash the two commits. (optional)\n\nAlternatively, as others have pointed out, the stash should work as well.\n"},{"id":"153494","messageId":"loom.20101014T095743-275@post.gmane.org","threadId":"25423","inReplyTo":"AANLkTinnYEnCwpTh45N69n73JQm=ndXH-SUJ5b1piUYv@mail.gmail.com","subject":"Re: Can I checkout a single file without altering index?","fromName":"Christian Halstrick","fromEmail":"christian.halstrick@gmail.com","sentAt":"2010-10-14T08:03:23Z","receivedAt":"2010-10-14T08:03:23Z","isPatch":false,"sender":{"key":"christian.halstrick@gmail.com","avatar":"https://gravatar.com/avatar/3598bf518644c7dc32d4dcd8e0554b6a313e12103011862402c83ae2854203ce?d=mp&s=160"},"body":"Thank's a lot for all your responses. I know now how to solve my problem. I'll\ndefinitely not going to commit my unit-test before my fix and publish that\nbecause then I would have commits in the history where tests fail. But other\nsuggested solutions do work.\n\nStill, all that sounds like workarounds for a lacking feature. Checkout content\nto the worktree without altering the index. What do you think, couldn't that be\nadded as an option to checkout?\n\n-- Chris\n"},{"id":"153592","messageId":"i9a6kn$d7o$1@dough.gmane.org","threadId":"25423","inReplyTo":"loom.20101014T095743-275@post.gmane.org","subject":"Re: Can I checkout a single file without altering index?","fromName":"Neal Kreitzinger","fromEmail":"neal@rsss.com","sentAt":"2010-10-15T18:30:06Z","receivedAt":"2010-10-15T18:30:06Z","isPatch":false,"sender":{"key":"neal@rsss.com","avatar":null},"body":"\"Christian Halstrick\" <christian.halstrick@gmail.com> wrote in message \nnews:loom.20101014T095743-275@post.gmane.org...\n> Thank's a lot for all your responses. I know now how to solve my problem. \n> I'll\n> definitely not going to commit my unit-test before my fix and publish that\n> because then I would have commits in the history where tests fail. But \n> other\n> suggested solutions do work.\n>\n> Still, all that sounds like workarounds for a lacking feature. Checkout \n> content\n> to the worktree without altering the index. What do you think, couldn't \n> that be\n> added as an option to checkout?\n>\n> -- Chris\n\nFWIW, my understanding of the index is that it is the middle-man for moving \nthings from your work-tree to the object-store AND for moving things from \nthe object-store to your work-tree.  Therefore, when you checkout the blob, \nit first gets copied from the object-store to your index and then from the \nindex to your work-tree.\n\nHowever, there is an option in git-commit to copy files directly from the \nworking-tree to the object-store by totally bypassing the index, but no one \nseems to do this or recommend doing this as normative practice.  None the \nless, this \"exception\" in the git-commit manpage does seem to set the \nprecedent, so maybe it is also conceivable to copy objects directly from the \nobject-store to the work-tree by totally bypassing the index.\n\nPlease note that I am responding because I am interested in the discussion \nand not because I know the answer.  I am not a git programmer so my \nobservations only symptomatic and/or theoretical as a user.\n\nv/r,\nNeal \n"},{"id":"153593","messageId":"20101015184302.GA22990@burratino","threadId":"25423","inReplyTo":"i9a6kn$d7o$1@dough.gmane.org","subject":"Re: Can I checkout a single file without altering index?","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2010-10-15T18:43:02Z","receivedAt":"2010-10-15T18:43:02Z","isPatch":false,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Hi Neal,\n\nNeal Kreitzinger wrote:\n\n> However, there is an option in git-commit to copy files directly from the \n> working-tree to the object-store by totally bypassing the index\n\nWhat option is this?  I thought \"git commit --include\" added content\nto the index.\n"},{"id":"153595","messageId":"20101015185539.GA30380@sigill.intra.peff.net","threadId":"25423","inReplyTo":"20101015184302.GA22990@burratino","subject":"Re: Can I checkout a single file without altering index?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2010-10-15T18:55:39Z","receivedAt":"2010-10-15T18:55:39Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, Oct 15, 2010 at 01:43:02PM -0500, Jonathan Nieder wrote:\n\n> Neal Kreitzinger wrote:\n> \n> > However, there is an option in git-commit to copy files directly from the \n> > working-tree to the object-store by totally bypassing the index\n> \n> What option is this?  I thought \"git commit --include\" added content\n> to the index.\n\ngit commit -o|--only, which is the same as \"git commit <paths>\". Of\ncourse it still uses an index, to create the tree, but it uses a\ntemporary one based on HEAD instead of the current index contents.\n\n-Peff\n"},{"id":"153596","messageId":"i9a88i$k3g$1@dough.gmane.org","threadId":"25423","inReplyTo":"20101015184302.GA22990@burratino","subject":"Re: Can I checkout a single file without altering index?","fromName":"Neal Kreitzinger","fromEmail":"neal@rsss.com","sentAt":"2010-10-15T18:57:46Z","receivedAt":"2010-10-15T18:57:46Z","isPatch":false,"sender":{"key":"neal@rsss.com","avatar":null},"body":"\"Jonathan Nieder\" <jrnieder@gmail.com> wrote in message \nnews:20101015184302.GA22990@burratino...\n> Hi Neal,\n>\n> Neal Kreitzinger wrote:\n>\n>> However, there is an option in git-commit to copy files directly from the\n>> working-tree to the object-store by totally bypassing the index\n>\n> What option is this?  I thought \"git commit --include\" added content\n> to the index.\n\n>From the git-commit manpage (1.7.1.2):\n\n\"3.  by listing files as arguments to the commit command, in which case the \ncommit will ignore changes staged in the index, and instead record the \ncurrent content of the listed files (which must already be known to git); \"\n\n(I haven't tried it myself because to me the index is a key technology of \ngit so I'm not sure why I would want to bypass it.)\n\nv/r,\nNeal \n"},{"id":"153597","messageId":"m2zkufcma2.fsf@igel.home","threadId":"25423","inReplyTo":"i9a6kn$d7o$1@dough.gmane.org","subject":"Re: Can I checkout a single file without altering index?","fromName":"Andreas Schwab","fromEmail":"schwab@linux-m68k.org","sentAt":"2010-10-15T19:02:13Z","receivedAt":"2010-10-15T19:02:13Z","isPatch":false,"sender":{"key":"schwab@linux-m68k.org","avatar":"https://avatars.githubusercontent.com/u/2175493?v=4"},"body":"\"Neal Kreitzinger\" <neal@rsss.com> writes:\n\n> However, there is an option in git-commit to copy files directly from the \n> working-tree to the object-store by totally bypassing the index, but no one \n> seems to do this or recommend doing this as normative practice.  None the \n> less, this \"exception\" in the git-commit manpage does seem to set the \n> precedent, so maybe it is also conceivable to copy objects directly from the \n> object-store to the work-tree by totally bypassing the index.\n\nYou can always do \"git cat-file blob <object>\", though you have to\nredirect output manually.\n\nAndreas.\n\n-- \nAndreas Schwab, schwab@linux-m68k.org\nGPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5\n\"And now for something completely different.\"\n"},{"id":"153599","messageId":"20101015193252.GA23082@burratino","threadId":"25423","inReplyTo":"20101015185539.GA30380@sigill.intra.peff.net","subject":"Re: Can I checkout a single file without altering index?","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2010-10-15T19:32:52Z","receivedAt":"2010-10-15T19:32:52Z","isPatch":false,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Jeff King wrote:\n> On Fri, Oct 15, 2010 at 01:43:02PM -0500, Jonathan Nieder wrote:\n>> Neal Kreitzinger wrote:\n\n>>> However, there is an option in git-commit to copy files directly from the \n>>> working-tree to the object-store by totally bypassing the index\n>>\n>> What option is this?  I thought \"git commit --include\" added content\n>> to the index.\n>\n> git commit -o|--only, which is the same as \"git commit <paths>\". Of\n> course it still uses an index, to create the tree, but it uses a\n> temporary one based on HEAD instead of the current index contents.\n\nAh, it's stranger than that.\n\n\t * A partial commit.\n\t *\n\t * (0) find the set of affected paths;\n\t * (1) get lock on the real index file;\n\t * (2) update the_index with the given paths;\n\t * (3) write the_index out to the real index (still locked);\n\t * (4) get lock on the false index file;\n\t * (5) reset the_index from HEAD;\n\t * (6) update the_index the same way as (2);\n\t * (7) write the_index out to the false index file;\n\t * (8) return the name of the false index file (still locked);\n\nThe net effect being that the index will match the work tree for the\nlisted paths when the operation is over, while other files are\nuntouched.\n-- 8< --\nSubject: Documentation: clarify \"commit --only\" description\n\n>From the current description, one might imagine that \"git commit\n<pathspec>\" bypasses the index completely.  Clarify what it does\ndo to the index:\n\n - paths matching <pathspec> are updated to match the work tree\n - paths not matching <pathspec> are left alone\n\nso readers can have a better idea of what the index represents\nbefore and after such an operation.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n I'm not so happy with the wording.  Hopefully this gives the idea...\n\ndiff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt\nindex 42fb1f5..6bb3eff 100644\n--- a/Documentation/git-commit.txt\n+++ b/Documentation/git-commit.txt\n@@ -191,9 +191,10 @@ FROM UPSTREAM REBASE\" section in linkgit:git-rebase[1].)\n --only::\n \tMake a commit only from the paths specified on the\n \tcommand line, disregarding any contents that have been\n-\tstaged so far. This is the default mode of operation of\n-\t'git commit' if any paths are given on the command line,\n-\tin which case this option can be omitted.\n+\tstaged so far.  The state of other files in the index is\n+\tpreserved and will not affect the commit.  This is the\n+\tdefault mode of operation of 'git commit' if any paths are given\n+\ton the command line, in which case this option can be omitted.\n \tIf this option is specified together with '--amend', then\n \tno paths need to be specified, which can be used to amend\n \tthe last commit without committing changes that have\n"},{"id":"153600","messageId":"20101015194851.GA31131@sigill.intra.peff.net","threadId":"25423","inReplyTo":"20101015193252.GA23082@burratino","subject":"Re: Can I checkout a single file without altering index?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2010-10-15T19:48:51Z","receivedAt":"2010-10-15T19:48:51Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, Oct 15, 2010 at 02:32:52PM -0500, Jonathan Nieder wrote:\n\n> > git commit -o|--only, which is the same as \"git commit <paths>\". Of\n> > course it still uses an index, to create the tree, but it uses a\n> > temporary one based on HEAD instead of the current index contents.\n> \n> Ah, it's stranger than that.\n> \n> \t * A partial commit.\n> \t *\n> \t * (0) find the set of affected paths;\n> \t * (1) get lock on the real index file;\n> \t * (2) update the_index with the given paths;\n> \t * (3) write the_index out to the real index (still locked);\n> \t * (4) get lock on the false index file;\n> \t * (5) reset the_index from HEAD;\n> \t * (6) update the_index the same way as (2);\n> \t * (7) write the_index out to the false index file;\n> \t * (8) return the name of the false index file (still locked);\n> \n> The net effect being that the index will match the work tree for the\n> listed paths when the operation is over, while other files are\n> untouched.\n\nWell, yeah, it does have to update those files in the regular index. Any\nother semantics would be insane; the change would appear reverted\nlooking at the difference between HEAD and the index.\n\nWith respect to your proposed change:\n\n> diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt\n> index 42fb1f5..6bb3eff 100644\n> --- a/Documentation/git-commit.txt\n> +++ b/Documentation/git-commit.txt\n> @@ -191,9 +191,10 @@ FROM UPSTREAM REBASE\" section in linkgit:git-rebase[1].)\n>  --only::\n>  \tMake a commit only from the paths specified on the\n>  \tcommand line, disregarding any contents that have been\n> -\tstaged so far. This is the default mode of operation of\n> -\t'git commit' if any paths are given on the command line,\n> -\tin which case this option can be omitted.\n> +\tstaged so far.  The state of other files in the index is\n> +\tpreserved and will not affect the commit.  This is the\n> +\tdefault mode of operation of 'git commit' if any paths are given\n> +\ton the command line, in which case this option can be omitted.\n\nI always assumed that \"disregarding any contents that have been staged\"\nmeant \"we will leave unmentioned paths alone\". But I don't think it\nhurts to be explicit. So your change looks fine to me.\n\n-Peff\n"},{"id":"153607","messageId":"7viq13avn0.fsf@alter.siamese.dyndns.org","threadId":"25423","inReplyTo":"i9a6kn$d7o$1@dough.gmane.org","subject":"Re: Can I checkout a single file without altering index?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-10-15T23:22:59Z","receivedAt":"2010-10-15T23:22:59Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Neal Kreitzinger\" <neal@rsss.com> writes:\n\n> FWIW, my understanding of the index is that it is the middle-man for moving \n> things from your work-tree to the object-store AND for moving things from \n> the object-store to your work-tree.\n\nWhile there is nothing technically incorrect in the above, it probably\nis easier to explain/understand why it works in the direction from the\nobject store and to the working tree if you state it this way instead:\n\n  The index is where you build the contents for your next commit.\n\n   - You build your next commit starting from the current commit,\n     so when you do \"checkout\" from the object store, both the\n     index and the working tree are populated with the blob.\n\n   - You then modify that state in your working tree, hopefully\n     testing, reviewing, and thinking about your change while\n     doing so.\n\n   - There may be good changes, not good enough changes, and\n     perhaps only for debugging changes in your working tree.  You\n     can decide to make commits out of only the good bits, leaving\n     others uncommitted.  You add only good bits to your next\n     commit, and the command to do so is naturally called \"git\n     add\" (and \"git add -p\" for add changes to a file partially by\n     picking patch hunks).\n\n   - There may be a time where you regret that some changes you\n     made to your working tree are not good, and want to start\n     over.  You may even do so after you added some changes to\n     the index (i.e. your next commit).  By checking the path\n     out of the current commit would give you the original\n     version of the path both in the index and in the working\n     tree file to help you start over.\n\n   - After making that commit, you will keep working to create\n     the commit next to that commit you created.  To help you\n     work incrementally, the index at that point contains what\n     you committed.\n \n> However, there is an option in git-commit to copy files directly from the \n> working-tree to the object-store by totally bypassing the index, but no one \n> seems to do this or recommend doing this as normative practice.\n\nThis is wrong.  People do this all the time with \"git commit $path\".\n\nWhat happens behind the scene is:\n\n - git prepares a temporary index that matches the contents of the\n   current commit;\n\n - the contents for $path from the working tree is then added to that\n   temporary index;\n\n - a new commit is written out of that temporary index; and\n\n - the $path is also added to the real index (this is a very important\n   detail---otherwise the next commit will lose the change to $path).\n\nNotice that in no step the index is really bypassed.  Everything\nliterally goes through the index.\n\nIf you want to bypass the index, you can do so with cat-file or show; it\njust is not a useful operation in a normal workflow of building the next\ncommit on top of the current one, and that is the only reason why there\nis no option such as \"checkout --no-index HEAD~47 path\".  If somebody\ncan write a convincing use case that shows why it is useful, such an\noption shouldn't be very hard to add.  But I don't think of any.  For\nexample, this is not it:\n\n    I start from a clean slate and start working.\n\n    $ git checkout\n    $ edit; git diff; compile; test; git add path ;# repeat\n\n    At this point I have some cooked contents added for the next commit\n    in the index for path.  But I realize that the contents of that path\n    in another branch might be even better.  But I do not want to lose\n    the state I arrived at, which might be better than that alternative.\n    I cannot decide, so I'll keep that in the index for now.\n\n    $ git checkout --no-index the-other-branch path\n    $ edit; compile; test; ...\n\n    case I. yes the other one indeed is better\n    $ git add path\n\n    case II. no the other one is inferiour\n    $ git checkout path ;# out of index\n\nWhile superficially this looks promising, this is unwieldy.  For one\nthing, you cannot easily check what you changed anymore, as \"git diff\npath\" would show the difference between the index, i.e. a version that\nwas modified in a different way from the current version, and the\nworking tree, i.e. another version that was modified starting from a\ntotally different version in the-other-branch.\n"},{"id":"153615","messageId":"20101015234008.GC25624@burratino","threadId":"25423","inReplyTo":"7viq13avn0.fsf@alter.siamese.dyndns.org","subject":"Re: Can I checkout a single file without altering index?","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2010-10-15T23:40:08Z","receivedAt":"2010-10-15T23:40:08Z","isPatch":false,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Junio C Hamano wrote:\n\n>                                                           If somebody\n> can write a convincing use case that shows why it is useful, such an\n> option shouldn't be very hard to add.  But I don't think of any.  For\n> example, this is not it:\n> \n>     I start from a clean slate and start working.\n> \n>     $ git checkout\n>     $ edit; git diff; compile; test; git add path ;# repeat\n> \n>     At this point I have some cooked contents added for the next commit\n>     in the index for path.  But I realize that the contents of that path\n>     in another branch might be even better.  But I do not want to lose\n>     the state I arrived at, which might be better than that alternative.\n>     I cannot decide, so I'll keep that in the index for now.\n\nTo be a devil's advocate (because I am not convinced yet), here is one:\n\n    I start from a clean slate and start working.\n\n    $ git checkout\n    $ edit; git diff; compile; test; git add path ;# repeat\n\n    At this point I have some cooked contents added for the next commit\n    in the index for path.  Illustrating the new change is a new test,\n    and I want to \"test the test\" by trying it out against the inferior\n    previous state.\n\n    $ git checkout --no-index HEAD path\n    $ test; edit test; git diff; compile; test; git add test ;# repeat\n\n    Now one last test run with the improved state\n\n    $ git checkout path\n    $ compile; test\n    $ git commit\n"}]}