正在构思这篇新的文章,介绍如何在抛开服务器、帐户、SSH、读写权限等等干扰,在本地相对安全的实现一个干净清洁的 Git 使用环境。 先简单记录一下实际过程,有时间再进行细节的补充。 1、安装 Git 具体步骤请参考我的另外一篇文章:《从 Emacs 到 GitHub》
1 http://blog.williamyao.com/archives/2272、生成本地一个纯净的 Git 仓库 因为本文介绍的 Git 使用环境是抛开了一切分布式服务器环境,单纯本地使用,为了尽可能避免仓库损坏带来不可挽回的损失,也为了达到相对安全的使用环境,我在实例环境中是这样进行描述的: Git 的共享仓库,都放在使用 TrueCrypt 加密后的虚拟分区中:
1 /Volumes/"TrueCrypt Volume"/Git而 TrueCrypt 的虚拟磁盘镜像文件存储在移动硬盘上。 当然,如果没有加密需要,可以将共享仓库直接放在移动硬盘中,比如:
1 /mnt/projects/Git实例中,当前项目为 Diary,存放在下边位置:
1 ~/Projects/DiaryDiary 项目中仅有一个文件:README 介绍了本文实例中的规则之后,我们开始生成纯净 Git 仓库的具体步骤: 首先进入 Diary 项目目录,将该目录初始化为 Git 仓库,并将该项目目录中所有文件加入 Git 监控(其实就 README 一个文件),然后进行第一次提交操作:
1 2 3 4 $ cd ~/Projects/Diary $ git init $ git add * $ git commit -m "The first commit of Project: Diary"这样,Diary 项目已经是一个带有 Git 版本控制的目录了,并且该仓库已经进行了第一次成功的提交。 接下来,利用这个已经变成带有 Git 版本控制功能的 Diary 项目目录,生成一个纯净的不带任何项目文件,只有 .git 目录的 Git 仓库:
1 2 $ cd ~/Projects $ git clone --bare Diary Diary.git然后,将该纯净仓库复制到我们的加密虚拟磁盘中:
1 2 $ mkdir /Volumes/"TrueCrypt Volumes"/Git $ cp ~/Projects/Diary.git /Volumes/"TrueCrypt Volume"/Git/这样,我们 Diary 项目的原始纯净仓库,就已经被安全的保护在了 TrueCrypt 虚拟磁盘中的 Git 目录中了。 接下来,也是最后一步,删掉原来的 Diary 项目,重新从纯净仓库中 clone 出新的副本:
1 2 3 $ cd ~/Projects $ rm -f -r Diary $ git clone file:///Volumes/ "TrueCrypt Volume"/Git/Diary.git大功告成,目前的项目状态就是: 当前工作副本是 ~/Projects/Diary,原始仓库是 /Volumes/”TrueCrypt Volume”/Git/,当你愉快的工作了一个星期,进行了若干次 commit 提交操作,到了周末需要备份项目的时候(虽然一个星期备份一次是很不好的习惯,最好一天一次),只需要挂载上 TrueCrypt 分区,然后:
1 2 3 $ cd ~/Projects/Diary $ git commit -m "Last commit and then push" $ git push你一周的辛苦工作,就已经被推送(push)到 TrueCrypt 分区中位于 Git/Diary.git 的原始仓库中去了。 当然,上边删除 Diary 原始目录并重新 clone,仅仅是为了方便快捷,和作为说明来用,另外一个可能会因为 Diary 中文件被更改而被 Git 拒绝推送的操作是:
1 2 3 4 5 6 $ cd ~/Projects/Diary $ git remote add origin file:///Volumes/ "TrueCrypt Volume"/Git/Diary.git $ git commit -m "Last commit and then push" $ git push origin master 或者 $ git push
转自 http://blog.williamyao.com/archives/232
Written on July 21st, 2010 , Ironware Tags: emacs , git , mac , truecrypt