像android一样的源码,一个源码就有10G,如果要想发送或者刻录,这么大的代码很难传输。因此,可以这样做:
0.先在根目录使用:git init。(注意,1.不要用--bare参数,纯版本仓库也会报错,说是没有work tree。2.也不要在命令后面加上目录,如:git init ../notbare。)
然后,提交commit
git add .
git commit -am "new"
不做这一步,相当于没有提交过commit给git仓库,.git实际还是一个空空如也的仓库,也就不会有branch,在checkout的时候会报错,说没有branch。第一次提交commit后,会产生master分支(branch)。后面在实例会展示这个操作。
同样道理,对.git的要求是有提交过commit的branch,如果你是从别的地方clone下一个git库,自然会有一个已经提交过commit的branch。这样,就不需要再次提交commit了,直接就可以进行下面的操作。
1.根目录下的.git复制一份。
2.压缩这个.git文件夹。linux中可以tar -cjf .git 会打包成一个v名字的文件,把它重命名为git.bz2。
3.发送给别人
4.别人获得git.bz2后,解压缩,得到.git。
5.在linux下看不到.开头的文件,因此要把.git放在一个工作路径下,可以先创建一个文件夹,把压缩包放在里面,然后在当前路径解压缩。或者使用tar -xjf git.bz2解压缩,我是图形界面解压缩,所以没验证这个指令的选项对不对。
6.在.git的同级目录下执行git checkout -f
记得不要进入.git目录,否则它会报错,fatal this operation must be run in a work tree。
整个过程中,压缩包只有2.3G,这样可以刻录到4G大小的光盘发送给别人了。
完整实例,copy两个文件Screentshot-1.png , Screenshot.png到新建的test2文件夹,然后通过git checkout -f在另一个文件夹new_dir复原:
norton@norton-laptop:~/work$ mkdir test2
norton@norton-laptop:~/work$ cp Screenshot* test2
norton@norton-laptop:~/work$ cd test2
norton@norton-laptop:~/work/test2$ ls
Screenshot-1.png Screenshot.png
norton@norton-laptop:~/work/test2$ git init
Initialized empty Git repository in /home/norton/work/test2/.git/
norton@norton-laptop:~/work/test2$ git add .
norton@norton-laptop:~/work/test2$ git commit -am "first commit"
[master (root-commit) ed37726] first commit
2 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 Screenshot-1.png
create mode 100644 Screenshot.png
norton@norton-laptop:~/work/test2$ git branch
* master
norton@norton-laptop:~/work/test2$ ls
Screenshot-1.png Screenshot.png
norton@norton-laptop:~/work/test2$ mkdir new_dir
norton@norton-laptop:~/work/test2$ mv .git/ new_dir/
norton@norton-laptop:~/work/test2$ cd new_dir/
norton@norton-laptop:~/work/test2/new_dir$ ll
total 12
drwxr-xr-x 3 norton norton 4096 2014-07-24 17:17 ./
drwxr-xr-x 3 norton norton 4096 2014-07-24 17:17 ../
drwxr-xr-x 8 norton norton 4096 2014-07-24 17:16 .git/
norton@norton-laptop:~/work/test2/new_dir$ git checkout -f
norton@norton-laptop:~/work/test2/new_dir$ ll
total 172
drwxr-xr-x 3 norton norton 4096 2014-07-24 17:17 ./
drwxr-xr-x 3 norton norton 4096 2014-07-24 17:17 ../
drwxr-xr-x 8 norton norton 4096 2014-07-24 17:17 .git/
-rw-r--r-- 1 norton norton 78788 2014-07-24 17:17 Screenshot-1.png
-rw-r--r-- 1 norton norton 79088 2014-07-24 17:17 Screenshot.png
norton@norton-laptop:~/work/test2/new_dir$
然后,我创建纯版本仓库,示范下错误
norton@norton-laptop:~/work/test2/new_dir$ rm .git/ -r
norton@norton-laptop:~/work/test2/new_dir$ ls
Screenshot-1.png Screenshot.png
norton@norton-laptop:~/work/test2/new_dir$ git init --bare .git
Initialized empty Git repository in /home/norton/work/test2/new_dir/.git/
norton@norton-laptop:~/work/test2/new_dir$ ll
total 172
drwxr-xr-x 3 norton norton 4096 2014-07-24 17:31 ./
drwxr-xr-x 3 norton norton 4096 2014-07-24 17:17 ../
drwxr-xr-x 7 norton norton 4096 2014-07-24 17:31 .git/
-rw-r--r-- 1 norton norton 78788 2014-07-24 17:17 Screenshot-1.png
-rw-r--r-- 1 norton norton 79088 2014-07-24 17:17 Screenshot.png
norton@norton-laptop:~/work/test2/new_dir$ mkdir test
norton@norton-laptop:~/work/test2/new_dir$ mv .git/ test/
norton@norton-laptop:~/work/test2/new_dir$ cd test/
norton@norton-laptop:~/work/test2/new_dir/test$ ls
norton@norton-laptop:~/work/test2/new_dir/test$ ll
total 12
drwxr-xr-x 3 norton norton 4096 2014-07-24 17:31 ./
drwxr-xr-x 3 norton norton 4096 2014-07-24 17:31 ../
drwxr-xr-x 7 norton norton 4096 2014-07-24 17:31 .git/
norton@norton-laptop:~/work/test2/new_dir/test$ git checkout -f
fatal: This operation must be run in a work tree
因为纯版本仓库是没有work tree的,我在.git的目录下测试结果如下:
norton@norton-laptop:~/work/test2/new_dir$ git add .
fatal: This operation must be run in a work tree