John White
John White

Reputation: 977

Creating quick snapshots of a repository (git?)

I searched for this a lot, but it's not clear whether git is the correct tool for what I want to do or not. When I write code I would like to create quick snapshots of the entire repository for testing stuff in various places. I forget where I add/edit the code, so a good thing would be to "revert" the whole repository to the initial state. And these snapshots need to be able to be maintained or deleted permanently, as these are just tests and experiments.

VM snapshots are slow and interrupt the connections. I was thinking about Git and its branching features. BUT as far as I can see git keeps everything forever, unless some special dangerous commands are given to delete stuff.

What I would like: Commit multiple snapshots, be able to switch between them and permanently delete them when I push everything to the online repository. I don't want to waste space on the repo because of useless code, with useless commits that clutter the view.

This might be a noob question, unfortunately every guide on the internet tells lots of commands and concepts with few real use cases.

Thanks a lot everyone

Upvotes: 5

Views: 1351

Answers (2)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 521609

Git sounds like an excellent choice for your use case. Unlike many other version control systems (VCS), Git is a repository or project based VCS. When you do a commit in Git, you essentially take a snapshot of your entire project, including every file. This stands in contrast to other VCS such as Perforce, where every file has its own history. Hence it is easy to move around your project from one state to the next in Git.

Another nice thing about Git is that it only stores the diff from one commit to the next (at least conceptually, in practice it persists a tree structure). So if you only change one file in your project from one commit to the next, then Git will only record the change to your project. This makes Git lean and mean, and there is no need to delete anything you might consider superuous; Git stores the smallest amount of information needed to get the job done. Conceptually, you can think of Git as taking one full snapshot of your entire project on the repository, and afterwards recording only the changes as they should occur.

Upvotes: 1

AnoE
AnoE

Reputation: 8345

When I write code I would like to create quick snapshots of the entire repository for testing stuff in various places.

Yes, git is very good for that.

And these snapshots need to be able to be maintained or deleted permanently, as these are just tests and experiments.

Branches will do that for you.

as far as I can see git keeps everything forever,

No, that is not true. It only keeps all commits that have a branch or tag associated with them, plus everything leading directly up to them. Other commits, which you can not reach via any branch or tag anymore will (after some time) automatically be deleted via garbage collection.

What I would like: Commit multiple snapshots, be able to switch between them and permanently delete them when I push everything to the online repository.

Yes, git branches.

I don't want to waste space on the repo because of useless code, with useless commits that clutter the view.

Yup, they will go away; and unless we are talking about Linux sized projects here, space should be no issue whatsoever.

This might be a noob question, unfortunately every guide on the internet tells lots of commands and concepts with few real use cases.

http://gitready.com/beginner/2009/02/17/how-git-stores-your-data.html is an excellent introduction; https://www.jayway.com/2013/03/03/git-is-a-purely-functional-data-structure/ has lots of details (read after the first link, may just be overkill for you).

Upvotes: 3

Related Questions