專案需要,在此搭建git伺服器對全志,rk,新岸線原始碼sdk進行管理。現整理文件以供交流學習。
一:搭建簡單無需許可權的git伺服器
sudo apt-get installgit-core openssh-server openssh-client
sudo apt-get install
git-daemon-run
②然後新增git 使用者:
sudo useradd-m -s /bin/bash -d /home/git git(-m 自動建立使用者目錄 /home/git -s 指定登入後所用shell -d 使用者登入後所預設進入的目錄)
sudo passwd git ---為了以後su git登陸好記密碼 我一樣用git
③配置git-daemon(配置後重啟:sudosv restart git-daemon)
sudovim /etc/sv/git-daemon/run
1 #!/bin/sh
2 exec 2>&1
3 echo 'git-daemon starting.'
4 #exec chpst -ugitdaemon \
5 # /usr/lib/git-core/git-daemon --export-all --base-path=/pub/gittrees /pub/gittrees
6exec /usr/lib/git-core/git-daemon --verbose --export-all --base-path=/pub/gittrees --enable=receive-pack
④測試伺服器上建立git倉庫
ubuntu@server:/pub/gittrees$ pwd
/pub/gittrees
ubuntu@server:/pub/gittrees$mkdir testpro
ubuntu@server:/pub/gittrees/testpro$git init
ubuntu@server:/pub/gittrees/testpro$echo "test project" > test.txt
ubuntu@server:/pub/gittrees/testpro$git add .
ubuntu@server:/pub/gittrees/testpro$git commit -a -m "init test project"
客戶端遠端轉殖服務上git倉庫
[mid@mid ~/work]$mkdir testgit
[mid@mid ~/work]$cd testgit
[mid@mid ~/work/testgit]$git clone git: (伺服器倉庫根目錄為/pub/gittrees,則伺服器遠端倉庫路徑為/pub/gittrees/testpro)
[mid@mid ~/work/testgit]$ls
testpro
[mid@mid ~/work/testgit/testpro]$ls
test.txt
[mid@mid ~/work/testgit/testpro]$vim test2.txt
[mid@mid ~/work/testgit/testpro]$git add .
[mid@mid ~/work/testgit/testpro]$git cm -a -m "add test2.txt by mid"
[mid@mid ~/work/testgit/testpro]$git push origin master
......
remote: error: 'receive.denycurrentbranch' configuration variable to 'refuse'.
to git:
! [remote rejected] master -> master (branch is currently checked out)
error: 無法推送一些引用到 'git:'
伺服器端檢視日誌分析:
ubuntu@server:/pub/gittrees/testpro$ cat/var/log/git-daemon/current
由於git預設拒絕了push操作,需要進行設定,修改.git/config檔案後面新增如下**:
ubuntu@server:/pub/gittrees/testpro$ vim .git/config
[receive]
denycurrentbranch = ignore
[mid@mid ~/work/testgit/testpro]$git push origin master
counting objects: 4, done.
delta compression using up to 8 threads.
compressing objects: 100% (2/2), done.
writing objects: 100% (3/3), 288 bytes | 0 bytes/s, done.
total 3 (delta 0), reused 0 (delta 0)
to git:
efe7f0f..756f1d5 master -> master
此時,伺服器端並不能檢視已經提交的test2.txt。必須得使用命令 git reset --hard 才能看到push後的內容
ubuntu@server:/pub/gittrees/testpro$ git reset --hard
ubuntu@server:/pub/gittrees/testpro$ ls
test2.txt test.txt
在初始化遠端倉庫時最好使用
git --bare init而不要使用:git init
ubuntu@server:/pub/gittrees$ mkdir test.git
ubuntu@server:/pub/gittrees$ cd test.git/
ubuntu@server:/pub/gittrees/test.git$
ubuntu@server:/pub/gittrees/test.git$ git init --bare
initialized empty git repository in /pub/gittrees/test.git/
ubuntu@server:/pub/gittrees/test.git$ ls
branches config description head hooks info objects refs
ubuntu@server:/pub/gittrees/test.git$
客服端轉殖遠端test.git倉庫:
[mid@mid ~/work/testgit]$git clone git:
正轉殖到 'test'...
warning: 您似乎轉殖了乙個空版本庫。
檢查連線... 完成。
[mid@mid ~/work/testgit]$ls
test testpro
[mid@mid ~/work/testgit/test]$git cm -a -m "add test.txt by mid"
[master(根提交) 325d762] add test.txt by mid
1 file changed, 1 insertion(+)
create mode 100644 test.txt
[mid@mid ~/work/testgit/test]$git push origin master
counting objects: 3, done.
writing objects: 100% (3/3), 230 bytes | 0 bytes/s, done.
total 3 (delta 0), reused 0 (delta 0)
to git:
* [new branch] master -> master
[mid@mid ~/work/testgit/test]$
常見錯誤:
1.git fatal: the remote end hung up unexpectedl
檢查/etc/sv/git-daemon/run的--base-path引數,確保和server的git目錄相同
2.git fatal no matching remote head
server上如果沒有任何commit,則會出現該錯誤
3.git 'receive-pack': service not enabled for
在/etc/sv/git-daemon/run的git-daemon命令中加入: --enable=receive-pack
ubuntu10 04 搭建 samba服務
1.安裝samba伺服器 sudo apt get insall samba 如果複製不行,用手動輸入 invalid operation insall sudo apt get install smbfs 2.新增使用者並修改密碼 useradd win passwd win 3.設定該使用者登入...
ubuntu10 04 LTS公升級git 版本
1.原始碼編譯公升級git版本 解除安裝源安裝git版本 apt get remove git git core sudo apt get install libcurl4 gnutls dev libexpat1 dev gettext libz dev libssl dev libssl dev...
Ubuntu10 04安裝Git異常彙總
ubuntu10.04安裝git異常彙總 背景知識 git是乙個開源的分布式版本控制系統,適用於高效 快速的處理各種專案版本的管理。git是linux torvalds為了幫助管理linux核心而開發的乙個開放原始碼的版本控制軟體。儘管最初git開發是為了輔助linux核心開發過程,但是現在git已...