Git 作为备份和版本控制系统
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2576198/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git as a backup and Version Control System
提问by gitnoob
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 一样,我也想备份它。
回答by David Wolever
I wrote a blog post about thisa while back:
Version control systems, with the possible exception of SourceSafe, are great at keeping track of code. 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.
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. 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.
版本控制系统(可能是 SourceSafe 除外)非常擅长跟踪代码。这是为什么?因为它们旨在跟踪代码。
不幸的是,一个好的 VCS的特性与构成一个好的备份系统的特性完全不同——而且通常是完全相反的。
以文件所有权为例。一个好的 VCS 会非常正确地忽略文件所有权:当我检查其他人的代码时,我应该是这些文件的所有者——而不是最初创建它们的任何 uid。另一方面,一个好的备份系统将尽其所能保留文件所有权:当我从备份中恢复时,我希望 /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
“正确”备份。
回答by rmk
Use rsync
for backup.
Use git
for version control.
使用rsync
备份。使用git
版本控制。
回答by Pareidolian
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. I haven't played with the bachintime-common backend commands but they all seem to be python.
我发现 backintime-gnome(glade/python,单独的后端?)适用于计划的增量备份,它适用于您的每日、每周、每月等。然后 Git 存储库用于源文件或其他更改关键数据把它包起来很好。我没有玩过 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)." -http://backintime.le-web.org/documentation/
我在 Ubuntu 中使用它,“请记住,Back In Time 只是一个 GUI。真正的魔法是由 rsync(拍摄快照和恢复)、diff(检查是否有变化)和 cp(制作硬链接)完成的。” -http://backintime.le-web.org/documentation/
回答by Laramie
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 或冷库。
回答by black666
You really want to use rsync to backup your data. Check out the following url for more information on rsync and also some examples on how to backup your data:
您确实想使用 rsync 来备份您的数据。查看以下 url 以获取有关 rsync 的更多信息以及有关如何备份数据的一些示例:
回答by hillu
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. (This rules out state files kept by "modern" desktop environments and almost everything that is stored as XML.) Everything else goes into .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.
这读起来很像我在做什么。我的主目录中有一个 git 存储库,但我使用它来仅跟踪那些我可以手动编辑的配置文件。(这排除了由“现代”桌面环境保存的状态文件以及几乎所有存储为 XML 的内容。)其他所有内容都进入.gitignore
. 曾几何时,我决定我的“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.
我不将此设置用于备份目的,而是用于在不同计算机上的帐户之间同步跟踪的文件,但我认为这也适用于备份。
回答by niken
Great idea, i actually use it daily and it works fantasticuntil 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. 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. Some files are "special" so you probably wanna exclude them by default, like stuff in /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. 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.
好主意,我实际上每天都在使用它,而且效果很好直到您的电脑在提交过程中崩溃并损坏您的存储库。第一次发生这种情况时,我花了一天时间来修复所有内容并恢复备份,您最终在此过程中学到了很多关于 git 内部的知识,所以这是一个额外的好处。假设您使用的是 linux,我建议将 .git 目录的本地副本备份到单独的驱动器或其他任何地方,然后在操作系统的 / 根目录下 git init 并使用 .gitignore 来控制版本化的内容。有些文件是“特殊的”,因此您可能希望默认排除它们,例如 /proc 中的内容。您可以准确地观察不同的软件对您的 fs 做了什么,回滚损坏的安装并跟踪配置、日志等是轻而易举的。我不知道为什么所有这些反对者都说“不要这样做”,因为我做到了,而且非常实用且非常棒。
回答by ChesuCR
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
. This will make the .git
folder much smaller if to make changes on large files:
如果您想上传包含大文件的项目,并且不希望为了获取旧文件而签出到以前的提交,您可以使用git lfs
. .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. Or even you can use both in a same project, tracking and keep changes only with the files you want.
此解决方案将是一种将 Git 项目作为备份的方法。或者,您甚至可以在同一个项目中同时使用两者,仅对所需文件进行跟踪和保留更改。
回答by ChesuCR
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!
下一步 7 压缩它,你就完成了!