{"thread":{"id":"22627","subject":"Individual file snapshots","startedAt":"2010-02-12T12:03:05Z","lastAt":"2010-02-13T18:58:19Z","messageCount":18,"participants":["Ron Garret","Peter Krefting","René Scharfe","Brian Gernhardt","Junio C Hamano","Mark Lodato","Larry D'Anna"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"134324","messageId":"ron1-CD3223.04030512022010@news.gmane.org","threadId":"22627","inReplyTo":null,"subject":"Individual file snapshots","fromName":"Ron Garret","fromEmail":"ron1@flownet.com","sentAt":"2010-02-12T12:03:05Z","receivedAt":"2010-02-12T12:03:05Z","isPatch":false,"sender":{"key":"ron1@flownet.com","avatar":null},"body":"Before I reinvent the wheel...\n\nI would like to be able to store snapshots of individual files without \nmaking a commit on the main branch.  The scenario is that I've written \nsome experimental code that I have decided not to keep as part of the \nmain project, but which I might want to refer back to some day.  Is \nthere any easy way of doing that in git?\n\nThanks,\nrg\n"},{"id":"134325","messageId":"alpine.DEB.2.00.1002121316260.10583@ds9.cixit.se","threadId":"22627","inReplyTo":"ron1-CD3223.04030512022010@news.gmane.org","subject":"Re: Individual file snapshots","fromName":"Peter Krefting","fromEmail":"peter@softwolves.pp.se","sentAt":"2010-02-12T12:18:09Z","receivedAt":"2010-02-12T12:18:09Z","isPatch":false,"sender":{"key":"peter@softwolves.pp.se","avatar":"https://avatars.githubusercontent.com/u/990764?v=4"},"body":"Ron Garret:\n\n> I would like to be able to store snapshots of individual files without \n> making a commit on the main branch.\n\n   git hash-object -w filename\n\nwill add the file to the object database, outputting it's hash value.\n\n   git tag mytag hashvalue\n\ncreates a tag \"mytag\" pointing to that file.\n\n   git show mytag\n\nwill output the file you put in.\n\n-- \n\\\\// Peter - http://www.softwolves.pp.se/\n"},{"id":"134361","messageId":"ron1-278C58.09242712022010@news.gmane.org","threadId":"22627","inReplyTo":"alpine.DEB.2.00.1002121316260.10583@ds9.cixit.se","subject":"Re: Individual file snapshots","fromName":"Ron Garret","fromEmail":"ron1@flownet.com","sentAt":"2010-02-12T17:24:27Z","receivedAt":"2010-02-12T17:24:27Z","isPatch":false,"sender":{"key":"ron1@flownet.com","avatar":null},"body":"In article <alpine.DEB.2.00.1002121316260.10583@ds9.cixit.se>,\n Peter Krefting <peter@softwolves.pp.se> wrote:\n\n> Ron Garret:\n> \n> > I would like to be able to store snapshots of individual files without \n> > making a commit on the main branch.\n> \n>    git hash-object -w filename\n> \n> will add the file to the object database, outputting it's hash value.\n> \n>    git tag mytag hashvalue\n> \n> creates a tag \"mytag\" pointing to that file.\n> \n>    git show mytag\n> \n> will output the file you put in.\n\nAh, cool!  Thanks.  I knew about git hash-object, but I did not know \nthat you could tag the resulting hash.  I thought you could only tag \ncommit objects.\n\nrg\n"},{"id":"134377","messageId":"4B75BD06.1010802@lsrfire.ath.cx","threadId":"22627","inReplyTo":"ron1-CD3223.04030512022010@news.gmane.org","subject":"Re: Individual file snapshots","fromName":"René Scharfe","fromEmail":"rene.scharfe@lsrfire.ath.cx","sentAt":"2010-02-12T20:41:42Z","receivedAt":"2010-02-12T20:41:42Z","isPatch":false,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Am 12.02.2010 13:03, schrieb Ron Garret:\n> Before I reinvent the wheel...\n> \n> I would like to be able to store snapshots of individual files without \n> making a commit on the main branch.  The scenario is that I've written \n> some experimental code that I have decided not to keep as part of the \n> main project, but which I might want to refer back to some day.  Is \n> there any easy way of doing that in git?\n\nYou could keep the experimental files (or changes) in a separate,\nprivate branch on your local repository.\n\nRené\n"},{"id":"134381","messageId":"ron1-519083.13253112022010@news.gmane.org","threadId":"22627","inReplyTo":"4B75BD06.1010802@lsrfire.ath.cx","subject":"Re: Individual file snapshots","fromName":"Ron Garret","fromEmail":"ron1@flownet.com","sentAt":"2010-02-12T21:25:32Z","receivedAt":"2010-02-12T21:25:32Z","isPatch":false,"sender":{"key":"ron1@flownet.com","avatar":null},"body":"In article <4B75BD06.1010802@lsrfire.ath.cx>,\n René Scharfe <rene.scharfe@lsrfire.ath.cx> wrote:\n\n> Am 12.02.2010 13:03, schrieb Ron Garret:\n> > Before I reinvent the wheel...\n> > \n> > I would like to be able to store snapshots of individual files without \n> > making a commit on the main branch.  The scenario is that I've written \n> > some experimental code that I have decided not to keep as part of the \n> > main project, but which I might want to refer back to some day.  Is \n> > there any easy way of doing that in git?\n> \n> You could keep the experimental files (or changes) in a separate,\n> private branch on your local repository.\n> \n> René\n\nYeah, I considered that.  The problem with that is that the actual \nprocess turns out to be pretty obtrusive.  The scenario is that I've \ndone a bunch of hacking on the main branch and I realize that it's going \nnowhere.  Nothing is working, everything is a horrible mess that's \nspinning wildly out of control.  I want to get rid of everything I've \ndone and start over from an earlier snapshot that I knew was working.  \nBut I also want to keep a copy of this current messy state around for \nreference just in case there's a snippet here and there that might be \nsalvageable later on.  I don't know of any easy way to save the messed \nup file onto another branch.  I'd have to save the file somewhere (in \nthe stash maybe?), check out the snapshot branch, retrieve the saved \nfile, do the commit, and then switch back to the main branch.\n\nBut maybe the right answer is to just write a script that does all that \nautomatically?\n\nrg\n"},{"id":"134382","messageId":"12B5BDAB-DD9C-4CED-9489-0773BF577DF3@silverinsanity.com","threadId":"22627","inReplyTo":"ron1-519083.13253112022010@news.gmane.org","subject":"Re: Individual file snapshots","fromName":"Brian Gernhardt","fromEmail":"benji@silverinsanity.com","sentAt":"2010-02-12T21:37:09Z","receivedAt":"2010-02-12T21:37:09Z","isPatch":false,"sender":{"key":"benji@silverinsanity.com","avatar":"https://gravatar.com/avatar/e06c101dbc25c68114d859b4a9ec7cf8a2c52fd2b0270ef0eac0e2e63ff22311?d=mp&s=160"},"body":"\nOn Feb 12, 2010, at 4:25 PM, Ron Garret wrote:\n\n> Yeah, I considered that.  The problem with that is that the actual \n> process turns out to be pretty obtrusive.  The scenario is that I've \n> done a bunch of hacking on the main branch and I realize that it's going \n> nowhere.  Nothing is working, everything is a horrible mess that's \n> spinning wildly out of control.  I want to get rid of everything I've \n> done and start over from an earlier snapshot that I knew was working.  \n> But I also want to keep a copy of this current messy state around for \n> reference just in case there's a snippet here and there that might be \n> salvageable later on.  I don't know of any easy way to save the messed \n> up file onto another branch.  I'd have to save the file somewhere (in \n> the stash maybe?), check out the snapshot branch, retrieve the saved \n> file, do the commit, and then switch back to the main branch.\n\nHave you tried creating a new branch without saving the state?\n\ngit checkout -b failed-experiment\ngit commit -a -m \"Back to the drawing board\"\ngit checkout master\n\nOr if a series of commits seem to have gone bad:\n\ngit commit -a -m \"Well, that didn't work.\"\ngit branch failed-experiment\ngit reset --hard origin/master # or other good state\n\nYou can of course replace the -a to commit with the needed \"git add <file>\" commands and leave off the -m to leave real messages about why it went bad using $EDITOR.\n\n~~ Brian"},{"id":"134386","messageId":"ron1-62D136.13570812022010@news.gmane.org","threadId":"22627","inReplyTo":"12B5BDAB-DD9C-4CED-9489-0773BF577DF3@silverinsanity.com","subject":"Re: Individual file snapshots","fromName":"Ron Garret","fromEmail":"ron1@flownet.com","sentAt":"2010-02-12T21:57:08Z","receivedAt":"2010-02-12T21:57:08Z","isPatch":false,"sender":{"key":"ron1@flownet.com","avatar":null},"body":"In article <12B5BDAB-DD9C-4CED-9489-0773BF577DF3@silverinsanity.com>,\n Brian Gernhardt <benji@silverinsanity.com> wrote:\n\n> On Feb 12, 2010, at 4:25 PM, Ron Garret wrote:\n> \n> > Yeah, I considered that.  The problem with that is that the actual \n> > process turns out to be pretty obtrusive.  The scenario is that I've \n> > done a bunch of hacking on the main branch and I realize that it's going \n> > nowhere.  Nothing is working, everything is a horrible mess that's \n> > spinning wildly out of control.  I want to get rid of everything I've \n> > done and start over from an earlier snapshot that I knew was working.  \n> > But I also want to keep a copy of this current messy state around for \n> > reference just in case there's a snippet here and there that might be \n> > salvageable later on.  I don't know of any easy way to save the messed \n> > up file onto another branch.  I'd have to save the file somewhere (in \n> > the stash maybe?), check out the snapshot branch, retrieve the saved \n> > file, do the commit, and then switch back to the main branch.\n> \n> Have you tried creating a new branch without saving the state?\n> \n> git checkout -b failed-experiment\n> git commit -a -m \"Back to the drawing board\"\n> git checkout master\n> \n> Or if a series of commits seem to have gone bad:\n> \n> git commit -a -m \"Well, that didn't work.\"\n> git branch failed-experiment\n> git reset --hard origin/master # or other good state\n> \n> You can of course replace the -a to commit with the needed \"git add <file>\" \n> commands and leave off the -m to leave real messages about why it went bad \n> using $EDITOR.\n\nThat would require a separate branch for every snapshot, no?  I want \nthis to be lightweight.  It's not so much the creation of a zillion \nbranches that bothers me, but having to come up with a new name every \ntime would be a real hassle.\n\nrg\n"},{"id":"134389","messageId":"7v1vgqksoz.fsf@alter.siamese.dyndns.org","threadId":"22627","inReplyTo":"ron1-62D136.13570812022010@news.gmane.org","subject":"Re: Individual file snapshots","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-02-12T22:14:20Z","receivedAt":"2010-02-12T22:14:20Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ron Garret <ron1@flownet.com> writes:\n\n>> Or if a series of commits seem to have gone bad:\n>> \n>> git commit -a -m \"Well, that didn't work.\"\n>> git branch failed-experiment\n>> git reset --hard origin/master # or other good state\n>> \n>> You can of course replace the -a to commit with the needed \"git add <file>\" \n>> commands and leave off the -m to leave real messages about why it went bad \n>> using $EDITOR.\n>\n> That would require a separate branch for every snapshot, no?  I want \n> this to be lightweight.  It's not so much the creation of a zillion \n> branches that bothers me, but having to come up with a new name every \n> time would be a real hassle.\n\nPerhaps \"stash\"?\n\nUsually stash is used to store \"diff between stash@{N}^1 and stash@{N}\",\nand \"stash pop\" or \"stash apply\" are geared toward that usage.  But you\ncan use it as a way to keep snapshots.  You would be interacting with\nthe stash differently, though.  E.g.\n\n\tgit diff stash@{4}\n\tgit diff origin/master stash@{2}\n\tgit checkout stash -- Makefile\n"},{"id":"134390","messageId":"C022F034-F60E-4E89-A174-DC0F53ADEC19@silverinsanity.com","threadId":"22627","inReplyTo":"ron1-62D136.13570812022010@news.gmane.org","subject":"Re: Individual file snapshots","fromName":"Brian Gernhardt","fromEmail":"benji@silverinsanity.com","sentAt":"2010-02-12T22:32:15Z","receivedAt":"2010-02-12T22:32:15Z","isPatch":false,"sender":{"key":"benji@silverinsanity.com","avatar":"https://gravatar.com/avatar/e06c101dbc25c68114d859b4a9ec7cf8a2c52fd2b0270ef0eac0e2e63ff22311?d=mp&s=160"},"body":"\nOn Feb 12, 2010, at 4:57 PM, Ron Garret wrote:\n\n> That would require a separate branch for every snapshot, no?  I want \n> this to be lightweight.  It's not so much the creation of a zillion \n> branches that bothers me, but having to come up with a new name every \n> time would be a real hassle.\n\nAhhhh...  You could just use the stash and use some kind of recognizable message: git stash Failed: fooed the bar badly\n\nOr you could make a stash-like snapshot branch?  The following sequence does something like that:\n\n  git add .\n  git commit -m \"Ooops\"\n  git branch -f\n  git reset --hard HEAD^\n\nAfter a few failures like that, you can look over all the snapshots with\n\n  git log -g snapshots\n\nBy default they will be kept around for 30 days, or the current setting of gc.reflogexpireunreachable.  If you want to keep a snapshot around for more than 30 days, you probably want to give it a real branch anyway.\n\nYou could either create a script that uses the above commands or a patch that makes git-stash take a --ref= argument and then set:\n\n  alias.snapshot = stash --ref=refs/snapshots\n\n~~ Brian"},{"id":"134392","messageId":"ron1-5EFFD7.14390512022010@news.gmane.org","threadId":"22627","inReplyTo":"C022F034-F60E-4E89-A174-DC0F53ADEC19@silverinsanity.com","subject":"Re: Individual file snapshots","fromName":"Ron Garret","fromEmail":"ron1@flownet.com","sentAt":"2010-02-12T22:39:05Z","receivedAt":"2010-02-12T22:39:05Z","isPatch":false,"sender":{"key":"ron1@flownet.com","avatar":null},"body":"In article <C022F034-F60E-4E89-A174-DC0F53ADEC19@silverinsanity.com>,\n Brian Gernhardt <benji@silverinsanity.com> wrote:\n\n> On Feb 12, 2010, at 4:57 PM, Ron Garret wrote:\n> \n> > That would require a separate branch for every snapshot, no?  I want \n> > this to be lightweight.  It's not so much the creation of a zillion \n> > branches that bothers me, but having to come up with a new name every \n> > time would be a real hassle.\n> \n> Ahhhh...  You could just use the stash and use some kind of recognizable \n> message: git stash Failed: fooed the bar badly\n> \n> Or you could make a stash-like snapshot branch?  The following sequence does \n> something like that:\n> \n>   git add .\n>   git commit -m \"Ooops\"\n>   git branch -f\n>   git reset --hard HEAD^\n> \n> After a few failures like that, you can look over all the snapshots with\n> \n>   git log -g snapshots\n> \n> By default they will be kept around for 30 days, or the current setting of \n> gc.reflogexpireunreachable.  If you want to keep a snapshot around for more \n> than 30 days, you probably want to give it a real branch anyway.\n> \n> You could either create a script that uses the above commands or a patch that \n> makes git-stash take a --ref= argument and then set:\n> \n>   alias.snapshot = stash --ref=refs/snapshots\n\n\nYes, I think the right answer is going to be something like this:\n\ngit symbolic-ref HEAD refs/heads/snapshots\ngit rm --cached -r .\ngit commit --allow-empty -m 'Snapshot branch'\n\nThen, to take a snapshot:\n\ngit branch snapshot\ngit checkout master -- path\ngit add path\ngit commit -a -m 'Snapshot of [path]'\ngit checkout master\n\n(All of that will be in a script of course.)\n\nAnd to rollback:\n\ngit checkout snapshot-[n] -- path\n\nOr something like that.  I haven't actually tried this yet, but it seems \nlike it ought to work.\n\nAm I right that 'git checkout branch' changes branches, but 'git \ncheckout branch -- path' doesn't?  That's very confusing.  Useful, but \nconfusing :)\n\nrg\n"},{"id":"134394","messageId":"ron1-0EA861.14414712022010@news.gmane.org","threadId":"22627","inReplyTo":"7v1vgqksoz.fsf@alter.siamese.dyndns.org","subject":"Re: Individual file snapshots","fromName":"Ron Garret","fromEmail":"ron1@flownet.com","sentAt":"2010-02-12T22:41:47Z","receivedAt":"2010-02-12T22:41:47Z","isPatch":false,"sender":{"key":"ron1@flownet.com","avatar":null},"body":"In article <7v1vgqksoz.fsf@alter.siamese.dyndns.org>,\n Junio C Hamano <gitster@pobox.com> wrote:\n\n> Ron Garret <ron1@flownet.com> writes:\n> \n> >> Or if a series of commits seem to have gone bad:\n> >> \n> >> git commit -a -m \"Well, that didn't work.\"\n> >> git branch failed-experiment\n> >> git reset --hard origin/master # or other good state\n> >> \n> >> You can of course replace the -a to commit with the needed \"git add \n> >> <file>\" \n> >> commands and leave off the -m to leave real messages about why it went bad \n> >> using $EDITOR.\n> >\n> > That would require a separate branch for every snapshot, no?  I want \n> > this to be lightweight.  It's not so much the creation of a zillion \n> > branches that bothers me, but having to come up with a new name every \n> > time would be a real hassle.\n> \n> Perhaps \"stash\"?\n> \n> Usually stash is used to store \"diff between stash@{N}^1 and stash@{N}\",\n> and \"stash pop\" or \"stash apply\" are geared toward that usage.  But you\n> can use it as a way to keep snapshots.  You would be interacting with\n> the stash differently, though.  E.g.\n> \n> \tgit diff stash@{4}\n> \tgit diff origin/master stash@{2}\n> \tgit checkout stash -- Makefile\n\nNo, I don't really want to usurp the stash for this.  But I think a \nseparate disjoint branch (with an empty root) will work.  I think I can \nuse git checkout to move the files back and forth between the main \nbranch and the snapshot branch without causing merge problems if the \nsnapshot branch is disjoint.\n\nrg\n"},{"id":"134398","messageId":"ca433831002121633j5b96049bs71e539c96397aff4@mail.gmail.com","threadId":"22627","inReplyTo":"ron1-5EFFD7.14390512022010@news.gmane.org","subject":"Re: Individual file snapshots","fromName":"Mark Lodato","fromEmail":"lodatom@gmail.com","sentAt":"2010-02-13T00:33:56Z","receivedAt":"2010-02-13T00:33:56Z","isPatch":false,"sender":{"key":"lodatom@gmail.com","avatar":"https://avatars.githubusercontent.com/u/58860?v=4"},"body":"Ron, I also could use a feature like this.  Sometimes I just have some\ncode that I don't want to just throw away, but it really doesn't go in\nthe history.  I usually just create a file called \"junk\" and add it to\n.git/info/excludes, but I'd rather have it stored in git.\n\nOn Fri, Feb 12, 2010 at 5:39 PM, Ron Garret <ron1@flownet.com> wrote:\n> Yes, I think the right answer is going to be something like this:\n>\n> git symbolic-ref HEAD refs/heads/snapshots\n> git rm --cached -r .\n> git commit --allow-empty -m 'Snapshot branch'\n>\n> Then, to take a snapshot:\n>\n> git branch snapshot\n> git checkout master -- path\n> git add path\n> git commit -a -m 'Snapshot of [path]'\n> git checkout master\n>\n> (All of that will be in a script of course.)\n>\n> And to rollback:\n>\n> git checkout snapshot-[n] -- path\n>\n> Or something like that.  I haven't actually tried this yet, but it seems\n> like it ought to work.\n\nI took your idea and ran with it.  In my version, I don't bother\nswitching branches and instead use plumbing commands to get the job\ndone.  (This prevents issues if there's a conflict from the old\ncommit.)  Also, I record HEAD as an additional parent of the commit,\nso I can see where the commit came from.\n\nI uploaded it as a Github Gist with a bunch of comments.  (It's much\nnicer to read it with syntax highlighting.)  You may be able to modify\nthis to suit your needs.  In particular, if you'd prefer it not to be\na real branch, you could change $BRANCH to /refs/snapshots/foo or\nsomething like that to hide it.\n\nhttp://gist.github.com/303142\n\nThe basic steps are:\n\nbackup .git/index\ngit add -a\ngit write-tree\ngit commit-tree\nrestore .git/index\n\nI don't know much about git's plumbing commands, so I'd be interested\nin hearing from git experts to see if what I'm doing is a good idea.\n\n> Am I right that 'git checkout branch' changes branches, but 'git\n> checkout branch -- path' doesn't?  That's very confusing.  Useful, but\n> confusing :)\n\nYes on both counts :)\n\n--\nMark\n"},{"id":"134399","messageId":"7v6362c672.fsf@alter.siamese.dyndns.org","threadId":"22627","inReplyTo":"ca433831002121633j5b96049bs71e539c96397aff4@mail.gmail.com","subject":"Re: Individual file snapshots","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-02-13T00:47:29Z","receivedAt":"2010-02-13T00:47:29Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Mark Lodato <lodatom@gmail.com> writes:\n\n> The basic steps are:\n>\n> backup .git/index\n> git add -a\n> git write-tree\n> git commit-tree\n> restore .git/index\n\nInstead of doing that, you might want to consider\n\n\tGIT_INDEX_FILE=...some-temporary-file...\n        export GIT_INDEX_FILE\n\nand run everything as if that is the index throughout your script.  That\nway, if your script ever failed in the middle, you won't have to worry\nabout a broken index file.\n"},{"id":"134405","messageId":"20100213030004.GA20863@cthulhu","threadId":"22627","inReplyTo":"ron1-62D136.13570812022010@news.gmane.org","subject":"Re: Individual file snapshots","fromName":"Larry D'Anna","fromEmail":"larry@elder-gods.org","sentAt":"2010-02-13T03:00:04Z","receivedAt":"2010-02-13T03:00:04Z","isPatch":false,"sender":{"key":"larry@elder-gods.org","avatar":"https://avatars.githubusercontent.com/u/3013304?v=4"},"body":"* Ron Garret (ron1@flownet.com) [100212 16:58]:\n> That would require a separate branch for every snapshot, no?  I want \n> this to be lightweight.  It's not so much the creation of a zillion \n> branches that bothers me, but having to come up with a new name every \n> time would be a real hassle.\n\nI like to keep a branch called 'archive' for crap that's not being actively used\nanymore, but that I don't to throw away.  Like failed experiments, or top-git\nbranches that have been merged.  I just merge -s ours all of it into archive and\nforget about it.\n\n       --larry\n"},{"id":"134410","messageId":"ron1-90D6E1.23013612022010@news.gmane.org","threadId":"22627","inReplyTo":"ca433831002121633j5b96049bs71e539c96397aff4@mail.gmail.com","subject":"Re: Individual file snapshots","fromName":"Ron Garret","fromEmail":"ron1@flownet.com","sentAt":"2010-02-13T07:01:36Z","receivedAt":"2010-02-13T07:01:36Z","isPatch":false,"sender":{"key":"ron1@flownet.com","avatar":null},"body":"In article \n<ca433831002121633j5b96049bs71e539c96397aff4@mail.gmail.com>,\n Mark Lodato <lodatom@gmail.com> wrote:\n\n> Ron, I also could use a feature like this.  Sometimes I just have some\n> code that I don't want to just throw away, but it really doesn't go in\n> the history.  I usually just create a file called \"junk\" and add it to\n> .git/info/excludes, but I'd rather have it stored in git.\n> \n> On Fri, Feb 12, 2010 at 5:39 PM, Ron Garret <ron1@flownet.com> wrote:\n> > Yes, I think the right answer is going to be something like this:\n> >\n> > git symbolic-ref HEAD refs/heads/snapshots\n> > git rm --cached -r .\n> > git commit --allow-empty -m 'Snapshot branch'\n> >\n> > Then, to take a snapshot:\n> >\n> > git branch snapshot\n> > git checkout master -- path\n> > git add path\n> > git commit -a -m 'Snapshot of [path]'\n> > git checkout master\n> >\n> > (All of that will be in a script of course.)\n> >\n> > And to rollback:\n> >\n> > git checkout snapshot-[n] -- path\n> >\n> > Or something like that.  I haven't actually tried this yet, but it seems\n> > like it ought to work.\n> \n> I took your idea and ran with it.  In my version, I don't bother\n> switching branches and instead use plumbing commands to get the job\n> done.  (This prevents issues if there's a conflict from the old\n> commit.)  Also, I record HEAD as an additional parent of the commit,\n> so I can see where the commit came from.\n> \n> I uploaded it as a Github Gist with a bunch of comments.  (It's much\n> nicer to read it with syntax highlighting.)  You may be able to modify\n> this to suit your needs.  In particular, if you'd prefer it not to be\n> a real branch, you could change $BRANCH to /refs/snapshots/foo or\n> something like that to hide it.\n> \n> http://gist.github.com/303142\n> \n> The basic steps are:\n> \n> backup .git/index\n> git add -a\n> git write-tree\n> git commit-tree\n> restore .git/index\n> \n> I don't know much about git's plumbing commands, so I'd be interested\n> in hearing from git experts to see if what I'm doing is a good idea.\n\nMoving the index around seems kinda hacky.  You probably want git-mktree.\n\nrg\n"},{"id":"134439","messageId":"ca433831002130713i5b015686k9f53911954858845@mail.gmail.com","threadId":"22627","inReplyTo":"7v6362c672.fsf@alter.siamese.dyndns.org","subject":"Re: Individual file snapshots","fromName":"Mark Lodato","fromEmail":"lodatom@gmail.com","sentAt":"2010-02-13T15:13:45Z","receivedAt":"2010-02-13T15:13:45Z","isPatch":false,"sender":{"key":"lodatom@gmail.com","avatar":"https://avatars.githubusercontent.com/u/58860?v=4"},"body":"On Fri, Feb 12, 2010 at 7:47 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> Mark Lodato <lodatom@gmail.com> writes:\n>\n>> The basic steps are:\n>>\n>> backup .git/index\n>> git add -a\n>> git write-tree\n>> git commit-tree\n>> restore .git/index\n>\n> Instead of doing that, you might want to consider\n>\n>        GIT_INDEX_FILE=...some-temporary-file...\n>        export GIT_INDEX_FILE\n>\n> and run everything as if that is the index throughout your script.  That\n> way, if your script ever failed in the middle, you won't have to worry\n> about a broken index file.\n\nIn the actual script, I copied the index file back if any error\noccured.  Still, your idea sounds better, so I just updated it to use\nthis variable instead.  I still remove the temporary file on error,\nbut if something goes wrong, at least the index won't be hosed.\n\n\nOn Sat, Feb 13, 2010 at 2:01 AM, Ron Garret <ron1@flownet.com> wrote:\n> Moving the index around seems kinda hacky.  You probably want git-mktree.\n\ngit-mktree is way too complicated.  I would have to parse the index\nand call git-mktree for each directory.  There is already a program to\ndo this: git-write-tree :)  Besides, using GIT_INDEX_FILE as suggested\nby Junio allows me to leave the original index file intact.\n\n--\nMark\n"},{"id":"134453","messageId":"ron1-E2C140.10413413022010@news.gmane.org","threadId":"22627","inReplyTo":"ca433831002130713i5b015686k9f53911954858845@mail.gmail.com","subject":"Re: Individual file snapshots","fromName":"Ron Garret","fromEmail":"ron1@flownet.com","sentAt":"2010-02-13T18:41:34Z","receivedAt":"2010-02-13T18:41:34Z","isPatch":false,"sender":{"key":"ron1@flownet.com","avatar":null},"body":"In article \n<ca433831002130713i5b015686k9f53911954858845@mail.gmail.com>,\n Mark Lodato <lodatom@gmail.com> wrote:\n\n> On Sat, Feb 13, 2010 at 2:01 AM, Ron Garret <ron1@flownet.com> wrote:\n> > Moving the index around seems kinda hacky.  You probably want git-mktree.\n> \n> git-mktree is way too complicated.  I would have to parse the index\n> and call git-mktree for each directory.\n\nYeah, but think of how studly you'll feel when you do that! ;-)\n\n> Besides, using GIT_INDEX_FILE as suggested\n> by Junio allows me to leave the original index file intact.\n\nYeah, that might actually be a better plan.\n\nrg\n"},{"id":"134455","messageId":"7vy6ixj73o.fsf@alter.siamese.dyndns.org","threadId":"22627","inReplyTo":"ca433831002130713i5b015686k9f53911954858845@mail.gmail.com","subject":"Re: Individual file snapshots","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-02-13T18:58:19Z","receivedAt":"2010-02-13T18:58:19Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Mark Lodato <lodatom@gmail.com> writes:\n\n> ...  Besides, using GIT_INDEX_FILE as suggested\n> by Junio allows me to leave the original index file intact.\n\nHeh, that is what the Professionals use ;-) It is used by git-stash.sh for\nexample.\n\nAspiring Porcelain authors would benefit greatly by learning from some of\nthe few remaining scripted Porcelain commands.  With the recent rewriting\nto many of the originally scripted ones in C, it may have become somewhat\nharder to learn the plumbing mechanisms and techniques that way, but we\nstill keep some older ones in contrib/examples directory for that purpose.\n"}]}