Re: Individual file snapshots

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxx> 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
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]