在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 -e OS=${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 1 fi IFS=`printf '\t\n\t'` for file in `git ls-files` do update_file_timestamp "$file" done
在client端
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