顯示具有 Git 標籤的文章。 顯示所有文章
顯示具有 Git 標籤的文章。 顯示所有文章

31 1月 2012

Git over Apache2 http server in Ubuntu 11.10

由於手邊的MBP年事已高(五歲多囉),而且RAM最大僅能加到3G,開了IDE與Browser後已經沒什麼多餘的能力來支撐一個VM了。所以把另一台NB裝上Ubuntu 11.10,並將常用的服務裝上去,順便做些更新的筆記。
先前也曾經有個安裝筆記GIT + Apache2 on Ubuntu 8.10 (1),但現在的Ubuntu安裝又更簡單些;主要是因為現在提供了git-http-backend,設定上可以更簡化了。

 

  1. 安裝apache 與 git
    sudo apt-get install apache2 git
    
    後期的Ubuntu 已將git-core更名為git,但是用git-core也沒問題啦。
  2. 建立相關人員帳號密碼,-c代表要建新檔,-m代表密碼要加密
    sudo htpasswd -cm /etc/apache2/passwd $username
    第二位成員起就不需要加-c,只要用-m即可
    sudo htpasswd -m /etc/apache2/passwd $username
  3. 建立git repositories目錄,依習慣,一定要先有repository root。
    sudo mkdir /srv/git
    再建要用的repository,並修改owner為www-data,$reponame代表repository的名稱,.git雖然可加可不加,但建議是要有,.git不會加到clone回來的目錄名稱上
    sudo git --bare init /srv/git/$reponame.git
    sudo chown -R www-data:www-data /srv/git/$reponame.git
  4. 建立dav_git.conf到/etc/apache2/mods-available,並link到/etc/apache2/mods-enabled,檔名可以隨意,但副檔名一定要是conf.
    cd /etc/apache2/mods-available
    sudo vim dav_git.conf

    編輯內容如下

    #若無設定GIT_HTTP_EXPORT_ALL,則在每個repository下必需有git-daemon-export-ok這個檔案才能被外部存取。
    SetEnv GIT_PROJECT_ROOT /srv/git
    SetEnv GIT_HTTP_EXPORT_ALL
    ScriptAlias /git/ /usr/lib/git-core/git-http-backend/
    #用Location的話代表讀寫都要認證,如果希望開放給anonymous讀取,請改用LocationMatch即可
    <Location /git>
            AuthType Basic
            AuthName "Git"
            Require valid-user
            AuthUserFile /etc/apache2/passwd
    </Location>
    
    建立link到/etc/apache2/mods-enabled
    cd /etc/apache2/mods-enabled
    sudo ln -s ../mods-available/dav_git.conf dav_git.conf
  5. 重起apache2即可

 

 

18 1月 2011

git ignore

  • (1)以#起始的該行資料會被當做註解
  • (2)使用Glog Pattern
    Glog patterns 相近於常見的Regular Expressions, 但是較為簡單,由於git在ignore裡使用的是glob patterns,所以還是需要稍為瞭解一下。
    • ?:代表任意的一個字元
    • *:代表任意數目的字元
    • {!ab}:必需不合於此pattern
    • {ab,bb,cx}:代表合於ab,bb,cx之一種pattern即可
    • [abc]:代表合於a,b,c中任一字元即可
    • [^abc]:代表必需不合於a,b,c中任一字元
  • (3)若要指出目錄請以"/"表示

 

下列是我常用的.gitignore內容

#Mac OSX Finder
.DS_Store
#Maven Build Folder : Target
target/
#Temp Folder
tmp/
#Log Folder or Files
log/
*.log

有些小地方比較有趣
例如想忽略repository目錄下的特定檔案,可以這樣表示
/eclipse.config
如果用了log/*.log,代表你是要忽略log目錄下,第一層檔名結尾為.log的檔案,但是/log/2010/11/12/ap.log就會被加入到repository中。
所以要忽略log目錄下包含子目錄的所有.log檔案,要這樣表示
log/**/*.log

不過如果要忽略特定目錄下的所有檔案,像是log目錄中的所有檔案,
雖然可以用這樣來表示
log/**/* (log本身這個目錄仍會被加入repository)
不過用
log/ (log本身這個目錄不會被加入repository)
會比較簡潔.... 
雖然意義上仍有不同

不過Git有些特性讓我比較困擾的,特別是空目錄不會被加到repository中,這點在最初設定時就會有些麻煩....

15 7月 2010

Step by Step : Github with EGit

(1)Create Github Repository
輸入你要的Project Name即可,在這用的是gitdemo



















Create repository成功後,github會提供repository存取的uri,你可以使用ssh或http,也可以給他人readonly的uri,接下來的操作我選擇使用ssh的uri進行clone與push



















(2) Import git repository and create eclipse project
要使用import的方式才能選到Git Repository相關的操作,為什麼用new project的方式就不行,這...






























選Project from Git






















直接按下Clone即可







填入ssh要用的uri,protocol改選為git+ssh,user就一定要填git










































輸入Local端git repository存放的位置,基本上就是你eclipse project要放的目錄,remote name雖然可以改,但非常不建議





















Eclipse 取得git repository的資訊後就開始要求eclipse project所需要的資料了,所以接下來就是建立eclipse project

先選取要用的git repository



















因為git repository裡面沒有任何已存在的eclipse project,所以在Method for project creation就選第二項,至於sharing project的部份,也請選取第二項。



















接下來就是真的create eclipse project了,在這我用的是create Maven project, 接下來填maven group id , artifact id的部份就不贄述了





















create project完成後,wizard會要求選取要share的project與git repository,也就是建立project 與 git repository的關連



















(3) First Commit
接下來就進行第一次的commit,
Git的操作是依git add -> git commit -> git push的順序來進行的。
所以先將project基本的檔案加進project裡,也許是些configuration files或是base classes
看起來似乎很不錯,但在目前這階段,你會發現你要經由egit 執行add file to staged都不成功,
這是有原因的,晚些再來看看怎麼解決吧,先利用egit 做commit的處理吧
選取team, 再選commit











再選取要commit檔案,eclipse project相關的檔案記得也要勾選以進行commit,否則以後其他人clone 這個repository時會無法直接使用eclipse產生project






















再來如果你想進行push,將剛才的改變push到github上,如果不選擇Custom URI而使用當前建好的origin remote會發生錯誤,這部份就要靠下一步解決囉

(4) Update Git Remote Configuration
先切換View到Git Repositories看看EGit為我們建立的Remote






馬上會發發現一件事,這個remote沒有push的uri




解決的方式就把它加上去吧,點選remote按右鍵,選Create Push










然後又會出現要輸入github repository uri的畫面(這不是鬼打牆!





















再來選取要Push的branch

記得要按下Add all branches spec























按下finish後再確認origin這個remote的properties,就會發現Push URI出現囉






這時再進行Push的操作就ok囉,下面就是Push的最後確認,按下Finish就會真的送到Github上囉
























最後再去檢查Github Repository,看到檔案都出現在Repository應該就沒問題了


24 3月 2010

Branch named master

git init --no branch created.
touch README
git add README -- still no branch created.
git commit -m 'first commit' -- create a new branch named 'master', you have no choose....
git remote add origin git@github.com:AccountName/reponame.git --you can change 'origin' to any word you like
git push origin master -- If you don't like 'master', you have to use 'git checkout -b' and 'git branch -d master' to remove master branch.


Blogo 測試

私以為Git File Lifecycle 是這樣的


18 9月 2009

碎碎唸(8)

一直來就想做件事,租個虛擬主機,掛個Apache + Subversion,這樣我在外頭也可以改改自High的demo,回家後也不用開MBP來sync程式到我的Desktop,但一方面是不確定是否能正常運作,一方面也不想多這筆開銷(在家用ADSL自己架?我可不想天天擔心家裡電器走火…),所以一直沒有付諸實行,但最近因為玩Ruby的關係,接觸到了GIT,發現有免錢的github,真是一整個高興!Eclipse上的pluging “egit”雖然有點不成材,但用git protocol來接github倒沒出什麼事,只可惜了我的iPhone 3GS,JB後裝的git 跟subversion 就沒什麼用了…

04 9月 2009

Ubuntu & git-daemon

既然git是distributed revision control system, 所以除了server外,每個開發人員也應該要有完整的git操作環境,但不是每個開發人員都需要有apache這種httpd server,還好git本身有提供git-daemon來讓開發人員交流手上的source clone,git-daemon很容易,指定base-path就好,但是如果希望開機時自動載入的話可以試試安裝下這個package:
sudo apt-get insall git-daemon-run
安裝好了之後改一下 /etc/sv/git-daemon/run, 將"--base-path=xxxx"指到你git repositories 的root path, 然後在每一個你要share出來的git repository中下一個指令建立magic file
touch git-daemon-export-ok
沒有git-daemon-export-ok這檔案的repository是不會被別人看到的.
再重起git-daemon即可囉
sudo /etc/init.d/git-daemon restart

05 8月 2009

GIT + Apache2 on Ubuntu 8.10 (1)

前言
很早前就聽過GIT這個分散式的VCS,但是因為Subversion對我而言實在相當夠用,一直沒有想要更換的念頭,直到最近開始用了JRuby 才有了用用看的念頭,花了點時間確認GIT可以透過Apache走HTTP/HTTPS來checkin/checkout,而且Maven的SCM也支援GIT, 就開始了跟GIT奮戰的過程,我想至少花了4小時才確認這個GIT的Service是可用的。主要是因為不熟GIT的command,無法確認是否正 常。

安裝
(0)由於我已經有安裝了Apache2與Subversion,所以略過Apache2及DAV module的安裝,並且採用Subversion的帳號密碼檔

(1)安裝git-core curl

$>sudo apt-get install git-core curl

這時執行

$>git --version

應該會出現下到訊息,代表git應該可以用了
git version 1.5.6.3

再來是建立curl會用到帳密

$>touch ~/.netrc
然後在.netrc中加入下列資料

machine localhost
login youraccount #same with subversion
password yourpassword #same with subversion

(2)建立GIT repository

$>sudo mkdir /var/lib/git #先建一個git root,再將其他repository放在其下
$>sudo mkdir /var/lib/git/repo1
$>cd /var/lib/git/repo1
$>sudo git --bare init
$>sudo git-update-server-info
$>sudo chmod +x hooks/post-update #在透過http commit後會自動執行git-update-server-info
你會看到下列這樣的訊息,代表init成功
Initialized empty Git repository in /var/lib/git/repo1/
再設定權限,讓Apache2可以存取
$>sudo chown www-data:www-data -R /var/lib/git

(3)enable apache2 dav_fs, dav module
$>sudo a2enmod dav_fs
$>sudo a2enmod dav
因為我已經有裝Subversion,想說應該不用設定才是,後來發現只有起用dav這個module,而dav_fs沒起用,就是不行
所以還是記得要確認一下

(4)config git dav
建立Apache2用的GIT DAV設定
$>sudo touch /etc/apache2/mods-available/dav_git.conf
$>sudo ln -s /etc/apache2/mods-available/dav_git.conf /etc/apache2/mods-enabled/dav_git.conf
然後修改/etc/apache2/mods-available/dav_git.conf,將在第2個Step中加入的GIT Repository設為DAV,並指定
HTTP連結路徑為/git/repo1

Alias /git "/var/lib/git"
<Location /git/repo1>
	DAV on
	AuthType Basic
	AuthName "Git Repository"
	AuthUserFile "/etc/apache2/dav_svn.passwd"
	Require valid-user
</Location>

(5)restart apache2

$>sudo /etc/init.d/apache2 restart
這時再用Browser連結http://localhost:8080/git/repo1/HEAD,輸入帳密後應該可以看見下列訊息
ref: refs/heads/master

(6)clone repo1
在任一空目錄下執行git clone

$>git clone http://localhost/git/repo1
應該可以看到
Initialized empty Git repository in /yourpath/repo1/.git/
warning: You appear to have cloned an empty repository.

(7)test commit

$>touch readme
$>git add readme
$>git commit -m "first"
[master (root-commit) 29db40b] first
0 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 readme
$>git push origin master
Fetching remote heads...
refs/
refs/heads/
refs/tags/
updating 'refs/heads/master'
from 0000000000000000000000000000000000000000
to 29db40b949a69400ea4377c28703b6073c91d785
sending 3 objects
done
Updating remote server info