Mc128k Mc128k - 4 months ago 9
Git Question

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

Answer

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).

Comments