如何建一個新的git project server and client心得

来源:互联网 发布:大数据网站 编辑:程序博客网 时间:2024/05/27 02:28

在server端

首先,創建一個名為 'git' 的用戶

$ sudo adduser git

現在可以用 --bare 選項運行 git init 來建立一個裸倉庫,這會初始化一個不包含工作目錄的倉庫。

$ cd ~ (如果現在打pwd,應該是在/home/git)$ mkdir project.git$ cd project.git$ git --bare init

git use commit times for timestamps

place it (as executable) in the file $GIT_DIR/.git/hooks/post-checkout:

复制代码

#filename:post-checkout
#!/bin/sh -eOS=${OS:-`uname`}old_rev="$1"new_rev="$2"get_file_rev() { git rev-list -n 1 "$new_rev" "$1"}if [ "$OS" = 'Linux' ]then update_file_timestamp() { file_time=`git show --pretty=format:%ai --abbrev-commit "$(get_file_rev "$1")" | head -n 1` touch -d "$file_time" "$1" }elif [ "$OS" = 'FreeBSD' ]then update_file_timestamp() { file_time=`date -r "$(git show --pretty=format:%at --abbrev-commit "$(get_file_rev "$1")" | head -n 1)" '+%Y%m%d%H%M.%S'` touch -h -t "$file_time" "$1" }else echo "timestamp changing not implemented" >&2 exit 1fiIFS=`printf '\t\n\t'`for file in `git ls-files`do update_file_timestamp "$file"done

 

复制代码

 

 

在client端

遞迴把.gitignore加入空的資料夾

 

复制代码
复制代码
Filename:.gitignore

1 # Ignore everything in this directory 2 * 3 # Except this file 4 !.gitignore
复制代码
复制代码

 

find ./* -type d -empty | xargs -i cp .gitignore {}

 

如此便可把空的資料夾加入git管控

 

 

 

复制代码
在client端$ cd myproject$ git init$ git add -f .$ git commit -m 'initial commit'$ git remote add origin git@gitserver:/opt/git/project.git$ git push origin master
复制代码

Force add the .gitignore file(See man git add:)

-f, --force       Allow adding otherwise ignored files.

上傳到git server後,變可以使用下面指令下載

$ git clone git@gitserver:/opt/git/project.git
0 0