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 13, 2010, 07:01 UTC
Message-ID
<ron1-90D6E1.23013612022010@news.gmane.org>
In-Reply-To
<ca433831002121633j5b96049bs71e539c96397aff4@mail.gmail.com>
In article 
<ca433831002121633j5b96049bs71e539c96397aff4@mail.gmail.com>,
 Mark Lodato <lodatom@gmail.com> wrote:
Show 53 quoted lines
> Ron, I also could use a feature like this.  Sometimes I just have some
> code that I don't want to just throw away, but it really doesn't go in
> the history.  I usually just create a file called "junk" and add it to
> .git/info/excludes, but I'd rather have it stored in git.
> 
> On Fri, Feb 12, 2010 at 5:39 PM, Ron Garret <ron1@flownet.com> wrote:
> > 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.
> 
> I took your idea and ran with it.  In my version, I don't bother
> switching branches and instead use plumbing commands to get the job
> done.  (This prevents issues if there's a conflict from the old
> commit.)  Also, I record HEAD as an additional parent of the commit,
> so I can see where the commit came from.
> 
> I uploaded it as a Github Gist with a bunch of comments.  (It's much
> nicer to read it with syntax highlighting.)  You may be able to modify
> this to suit your needs.  In particular, if you'd prefer it not to be
> a real branch, you could change $BRANCH to /refs/snapshots/foo or
> something like that to hide it.
> 
> http://gist.github.com/303142
> 
> The basic steps are:
> 
> backup .git/index
> git add -a
> git write-tree
> git commit-tree
> restore .git/index
> 
> I don't know much about git's plumbing commands, so I'd be interested
> in hearing from git experts to see if what I'm doing is a good idea.
Moving the index around seems kinda hacky.  You probably want git-mktree.
rg
Previous: Junio C HamanoNext: Larry D'Anna
Message 17 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.