Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating quick snapshots of a repository (git?)

Tags:

git

snapshot

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

like image 831
John White Avatar asked Aug 04 '16 12:08

John White


People also ask

How do I create a snapshot in git?

Creating a Git Snapshot RecordSelect your Git repository and Salesforce org. Set the branch. By default, the master branch is selected, but this can be changed to a branch of your choice. Choose the Git Snapshot Permissions, Allow Snapshots & Commits, Allow Snapshots Only or Allow Commits Only.

What does snapshot in git mean?

The term snapshot is used in the git reference site as well. It is the replacement term for "Revision". In other version control systems, changes to individual files are tracked and refered to as revisions, but with git you are tracking the entire workspace, so they use the term snapshot to denote the difference.

Does git use snapshots?

Git is a version control system: can record/save snapshots and track the content of a folder as it changes over time. Every time we commit a snapshot, Git records a snapshot of the entire project, saves it, and assigns it a version. These snapshots are kept inside a sub-folder called .

What is a commit a snapshot of all the files in the repository?

A commit is a snapshot in time. Each commit contains a pointer to its root tree, representing the state of the working directory at that time. The commit has a list of parent commits corresponding to the previous snapshots. A commit with no parents is a root commit and a commit with multiple parents is a merge commit.


2 Answers

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

like image 173
AnoE Avatar answered Oct 06 '22 11:10

AnoE


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.

like image 43
Tim Biegeleisen Avatar answered Oct 06 '22 12:10

Tim Biegeleisen