简体   繁体   English

Git 作为备份和版本控制系统

[英]Git as a backup and Version Control System

I want to use Git to backup my home drive, but I also want to use it as a version control system for projects that will be stored in my home drive.我想使用 Git 来备份我的主驱动器,但我也想将它用作将存储在我的主驱动器中的项目的版本控制系统。

How would I go about doing that?我该怎么做? Do I .gitignore all the projects root folders and make new repositories for them?我是否 .gitignore 所有项目根文件夹并为它们创建新的存储库?

Edit:编辑:

Ok I explained what I wanted wrongly.好的,我错误地解释了我想要的东西。 I want to have a history of changes made to my home drive like I can get with Git and I also want to back that up.我想拥有对我的主驱动器所做更改的历史记录,就像我可以使用 Git 一样,我也想备份它。

I wrote a blog post about this a while back: 不久前写了一篇关于此的博客文章

Version control systems, with the possible exception of SourceSafe, are great at keeping track of code.版本控制系统(可能是 SourceSafe 除外)非常擅长跟踪代码。 Why is that?这是为什么? Because they were designed to keep track of code .因为它们旨在跟踪代码

Unfortunately, though, the features of a good VCS are entirely different – and often exactly the opposite – of the features which make a good backup system.不幸的是,一个好的 VCS 的特性与构成一个好的备份系统的特性完全不同——而且通常正好相反

Take, for example, file ownership .文件所有权为例。 A good VCS will, very rightly, ignore file ownership : when I check out someone else's code, I should be the owner of those file - not whatever uid originally created them.一个好的 VCS 会非常正确地忽略文件所有权:当我检查其他人的代码时,我应该是这些文件的所有者——而不是最初创建它们的任何 uid。 A good backup system, on the other hand, will do everything in its power to preserve file ownership : when I restore from my backups, I want /etc/shaddow to be owned by root and /home/wolever/ to be owned by wolever.另一方面,一个好的备份系统会尽其所能保留文件所有权:当我从备份中恢复时,我希望 /etc/shaddow 归 root 所有,/home/wolever/ 归 wolever 所有.

BUT, if you really want to, check out bup - as far as I can tell, it does backup with git "right".但是,如果您真的想要,请查看bup - 据我所知,它确实使用git “正确”进行备份。

Use rsync for backup.使用rsync进行备份。 Use git for version control.使用git进行版本控制。

You really want to use rsync to backup your data.您确实想使用 rsync 来备份您的数据。 Check out the following url for more information on rsync and also some examples on how to backup your data:查看以下 url 以获取有关 rsync 的更多信息以及有关如何备份数据的一些示例:

http://www.sanitarium.net/golug/rsync_backups_2010.html http://www.sanitarium.net/golug/rsync_backups_2010.html

I've found the backintime-gnome (glade/python, separate backend?) to be good for scheduled incremental backups, it works for your daily, weekly, monthly etc.. Then Git repos for source files or other change-critical data would wrap it up nice.我发现 backintime-gnome(glade/python,单独的后端?)适用于计划的增量备份,它适用于您的每日、每周、每月等。然后 Git 存储库用于源文件或其他更改关键数据把它包起来很好。 I haven't played with the bachintime-common backend commands but they all seem to be python.我没有玩过 bachintime-common 后端命令,但它们似乎都是 python。

I'm using it in Ubuntu, "Keep in mind that Back In Time is just a GUI. The real magic is done by rsync (take snapshots and restore), diff (check if somethind changed) and cp (make hardlinks)."我在 Ubuntu 中使用它,“请记住,Back In Time 只是一个 GUI。真正的魔法是由 rsync(拍摄快照和恢复)、diff(检查是否有变化)和 cp(制作硬链接)完成的。” -http://backintime.le-web.org/documentation/ -http://backintime.le-web.org/documentation/

There are a few projects that aim to solve that problem:有几个项目旨在解决这个问题:

bup seems to have made the most progress: https://github.com/apenwarr/bup bup 好像进步最大: https : //github.com/apenwarr/bup

But you may also want to search for gibak or coldstorage.但您可能还想搜索 gibak 或冷库。

Great idea, i actually use it daily and it works fantastic until your pc crashes mid-commit and corrupts your repo.好主意,我实际上每天都在使用它,它运行得非常好,直到您的电脑在提交过程中崩溃并损坏了您的存储库。 First time that happened it took me a day to fix everything and restore backups, you end up learning quite a bit about git internals in the process so that's an added benefit.第一次发生这种情况时,我花了一天时间来修复所有内容并恢复备份,您最终在此过程中学到了很多关于 git 内部结构的知识,因此这是一个额外的好处。 Assuming you're on linux, I recommend having a local copy of the .git dir backed up on a separate drive or whatever, then git init at the / root of your os and use .gitignore to control what gets versioned.假设您使用的是 linux,我建议将 .git 目录的本地副本备份在单独的驱动器或其他任何地方,然后在操作系统的 / 根目录下 git init 并使用 .gitignore 来控制版本化的内容。 Some files are "special" so you probably wanna exclude them by default, like stuff in /proc.有些文件是“特殊的”,因此您可能希望默认排除它们,例如 /proc 中的内容。 You can watch exactly what different software is doing to your fs and rolling back broken installations and keeping track of configuration, logs, etc. is a breeze.您可以准确地观察不同的软件对您的 fs 做了什么,回滚损坏的安装并跟踪配置、日志等是轻而易举的。 I don't know why all these nay-sayers are saying "don't do it" because I did it and it's very practical and very awesome.我不知道为什么所有这些反对者都说“不要这样做”,因为我做到了,而且非常实用且非常棒。 Like I said only downside is corrupted repo when something unexpected happens, but if you prepare for that fixing a broken commit is just a matter of copying the pre-corrupted .git over the corrupted one.就像我说的,唯一的缺点是当发生意外情况时 repo 损坏,但是如果您准备修复损坏的提交,只需将预先损坏的 .git 复制到损坏的 .git 上即可。

That reads pretty much like what I'm doing.这读起来很像我在做什么。 I have a git repository in my home directory, but I use that to track only those configuration files that I can edit by hand.我的主目录中有一个 git 存储库,但我使用它来仅跟踪那些我可以手动编辑的配置文件。 (This rules out state files kept by "modern" desktop environments and almost everything that is stored as XML.) Everything else goes into .gitignore . (这排除了“现代”桌面环境保存的状态文件以及几乎所有存储为 XML 的内容。)其他所有内容都进入.gitignore Once upon a time, I decided that my "notes" directory and my ~/.emacs.d should go into their own repositories, so I created git repositories in those directories and had the main repository ignore them.曾几何时,我决定我的“notes”目录和我的~/.emacs.d应该进入它们自己的存储库,所以我在这些目录中创建了 git 存储库并让主存储库忽略它们。

I don't use this setup for backup purposes but to synchronize the tracked files between accounts on different machines, but I suppose that this could also work for backups.我不将此设置用于备份目的,而是用于在不同计算机上的帐户之间同步跟踪的文件,但我认为这也适用于备份。

On windows git-extensions as well as the gitGui allow you to clone a repository, which would allow you to make a backup without all the files in .gitignore.在 Windows 上,git-extensions 和 gitGui 允许您克隆存储库,这将允许您在没有 .gitignore 中的所有文件的情况下进行备份。

Next 7zip it up and you are done!下一步 7zip 它,你就完成了!

For the projects that you want to keep a close track or make some rollback, you can use git in a normal way.对于你想保持密切跟踪或进行一些回滚的项目,你可以正常使用git。

If you want to upload projects with large files and you don't want to be able to checkout to previous commits in order to get old files, you can use git lfs .如果您想上传包含大文件的项目,并且不想为了获取旧文件而签出到以前的提交,则可以使用git lfs This will make the .git folder much smaller if to make changes on large files:如果要对大文件进行更改,这将使.git文件夹小得多:

Git Large File Storage (LFS) replaces large files such as audio samples, videos, datasets, and graphics with text pointers inside Git, while storing the file contents on a remote server like GitHub.com or GitHub Enterprise. Git 大文件存储 (LFS)使用 Git 内部的文本指针替换音频样本、视频、数据集和图形等大文件,同时将文件内容存储在 GitHub.com 或 GitHub Enterprise 等远程服务器上。

This solution would be an approach to have a Git Project as a backup.此解决方案将是一种将 Git 项目作为备份的方法。 Or even you can use both in a same project, tracking and keep changes only with the files you want.或者,您甚至可以在同一个项目中同时使用两者,仅对您想要的文件进行跟踪和保留更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM