git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Individual file snapshots

From
RGRon Garret <ron1@flownet.com>
Date
Feb 12, 2010, 22:39 UTC
Message-ID
<ron1-5EFFD7.14390512022010@news.gmane.org>
In-Reply-To
<C022F034-F60E-4E89-A174-DC0F53ADEC19@silverinsanity.com>
In article <C022F034-F60E-4E89-A174-DC0F53ADEC19@silverinsanity.com>,
 Brian Gernhardt <benji@silverinsanity.com> wrote:
Show 30 quoted lines
> On Feb 12, 2010, at 4:57 PM, Ron Garret wrote:
> 
> > That would require a separate branch for every snapshot, no?  I want 
> > this to be lightweight.  It's not so much the creation of a zillion 
> > branches that bothers me, but having to come up with a new name every 
> > time would be a real hassle.
> 
> Ahhhh...  You could just use the stash and use some kind of recognizable 
> message: git stash Failed: fooed the bar badly
> 
> Or you could make a stash-like snapshot branch?  The following sequence does 
> something like that:
> 
>   git add .
>   git commit -m "Ooops"
>   git branch -f
>   git reset --hard HEAD^
> 
> After a few failures like that, you can look over all the snapshots with
> 
>   git log -g snapshots
> 
> By 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.
> 
> You could either create a script that uses the above commands or a patch that 
> makes git-stash take a --ref= argument and then set:
> 
>   alias.snapshot = stash --ref=refs/snapshots
Yes, I think the right answer is going to be something like this:

git symbolic-ref HEAD refs/heads/snapshots git rm --cached -r . git commit --allow-empty -m 'Snapshot branch'

Then, to take a snapshot:

git branch snapshot git checkout master -- path git add path git commit -a -m 'Snapshot of [path]' git checkout master

(All of that will be in a script of course.)
And to rollback:
git checkout snapshot-[n] -- path

Or something like that. I haven't actually tried this yet, but it seems like it ought to work.

Am I right that 'git checkout branch' changes branches, but 'git checkout branch -- path' doesn't? That's very confusing. Useful, but confusing :)

rg
Previous: Brian GernhardtNext: Mark Lodato
Message 11 of 18 in “Individual file snapshots”
  1. Ron GarretFeb 12, 2010
  2. Peter KreftingFeb 12, 2010
  3. Ron GarretFeb 12, 2010
  4. René ScharfeFeb 12, 2010
  5. Ron GarretFeb 12, 2010
  6. Brian GernhardtFeb 12, 2010
  7. Ron GarretFeb 12, 2010
  8. Junio C HamanoFeb 12, 2010
  9. Ron GarretFeb 12, 2010
  10. Brian GernhardtFeb 12, 2010
  11. Ron GarretFeb 12, 2010
  12. Mark LodatoFeb 13, 2010
  13. Junio C HamanoFeb 13, 2010
  14. Mark LodatoFeb 13, 2010
  15. Ron GarretFeb 13, 2010
  16. Junio C HamanoFeb 13, 2010
  17. Ron GarretFeb 13, 2010
  18. Larry D'AnnaFeb 13, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.