git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mark Lodato <lodatom@gmail.com>
To: Ron Garret <ron1@flownet.com>
Cc: git@vger.kernel.org
Subject: Re: Individual file snapshots
Date: Fri, 12 Feb 2010 19:33:56 -0500	[thread overview]
Message-ID: <ca433831002121633j5b96049bs71e539c96397aff4@mail.gmail.com> (raw)
In-Reply-To: <ron1-5EFFD7.14390512022010@news.gmane.org>

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.

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

Yes on both counts :)

--
Mark

  reply	other threads:[~2010-02-13  0:34 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-12 12:03 Individual file snapshots Ron Garret
2010-02-12 12:18 ` Peter Krefting
2010-02-12 17:24   ` Ron Garret
2010-02-12 20:41 ` René Scharfe
2010-02-12 21:25   ` Ron Garret
2010-02-12 21:37     ` Brian Gernhardt
2010-02-12 21:57       ` Ron Garret
2010-02-12 22:14         ` Junio C Hamano
2010-02-12 22:41           ` Ron Garret
2010-02-12 22:32         ` Brian Gernhardt
2010-02-12 22:39           ` Ron Garret
2010-02-13  0:33             ` Mark Lodato [this message]
2010-02-13  0:47               ` Junio C Hamano
2010-02-13 15:13                 ` Mark Lodato
2010-02-13 18:41                   ` Ron Garret
2010-02-13 18:58                   ` Junio C Hamano
2010-02-13  7:01               ` Ron Garret
2010-02-13  3:00         ` Larry D'Anna

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ca433831002121633j5b96049bs71e539c96397aff4@mail.gmail.com \
    --to=lodatom@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=ron1@flownet.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).