http://www.mikeheijmans.com/2008/04/make-git-svn-work-on-mac-osx-tiger/
After a few hours of googling and pull some hair out, I have finally figured out how to make git-svn work on Mac OSX 10.4 Tiger. If you have installed git on your Mac using mac-ports or source, you will find that running git-svn causes an error similar to this:
Can't locate SVN/Core.pm in @INC (@INC contains: /usr/local/lib/perl5/site_perl/5.8.6/darwin-thread-multi-2level /usr/local/lib/perl5/site_perl/5.8.6 /usr/local/lib/perl5/site_perl /sw/lib/perl5 /sw/lib/perl5/darwin /System/Library/Perl/5.8.6/darwin-thread-multi-2level /System/Library/Perl/5.8.6 /Library/Perl/5.8.6/darwin-thread-multi-2level /Library/Perl/5.8.6 /Library/Perl /Network/Library/Perl/5.8.6/darwin-thread-multi-2level /Network/Library/Perl/5.8.6 /Network/Library/Perl /System/Library/Perl/Extras/5.8.6/darwin-thread-multi-2level /System/Library/Perl/Extras/5.8.6 /Library/Perl/5.8.1 .) at /usr/bin/git-svn line 24.
This is because when you installed SVN it didn’t put the perl modules in the correct place. Here is a quick way to fix it.
mike@mikes-laptop$ locate SVN/Core.pm
In my case it was located in /usr/local/lib/svn-perl/SVN/Core.pm
Now we need to link that SVN directory in to your perl directory so perl can pick it up and use it. We will put it in /System/Library/Perl/Extras/5.8.6mike@mikes-laptop$ sudo ln -s /usr/local/lib/svn-perl/SVN /System/Library/Perl/Extras/5.8.6/SVN
Now if you run git-svn you will notice a different error that resembles this:
Can't locate loadable object for module SVN::_Core in @INC (@INC contains: /usr/local/lib/perl5/site_perl/5.8.6/darwin-thread-multi-2level /usr/local/lib/perl5/site_perl/5.8.6 /usr/local/lib/perl5/site_perl /sw/lib/perl5 /sw/lib/perl5/darwin /System/Library/Perl/5.8.6/darwin-thread-multi-2level /System/Library/Perl/5.8.6 /Library/Perl/5.8.6/darwin-thread-multi-2level /Library/Perl/5.8.6 /Library/Perl /Network/Library/Perl/5.8.6/darwin-thread-multi-2level /Network/Library/Perl/5.8.6 /Network/Library/Perl /System/Library/Perl/Extras/5.8.6/darwin-thread-multi-2level /System/Library/Perl/Extras/5.8.6 /Library/Perl/5.8.1 .) at /System/Library/Perl/Extras/5.8.6/SVN/Base.pm line 59
BEGIN failed--compilation aborted at /System/Library/Perl/Extras/5.8.6/SVN/Core.pm line 5.
Compilation failed in require at /usr/bin/git-svn line 24.
We just need to link the auto/svn directory as well. Use the prior base path but instead of SVN you use auto/svn. Like so:
mike@mikes-laptop$ sudo ln -s /usr/local/lib/svn-perl/auto/svn /System/Library/Perl/Extras/5.8.6/auto/svn
And there you have it. If you try running git-svn you should be presented with an available command list.
http://www.mikeheijmans.com/2008/04/trouble-commiting-using-git-svn-mac-osx-tiger/
recently ported the toobs project from sourceforge (SVN) to github (git). So in order to do this I had to get git-svn to work. So with my last post I showed how I got the application to run, however, if you try and commit changes back to svn (git-svn dcommit) you will most likely end up with this error:
Password for 'mike': Can't locate Term/ReadKey.pm in @INC (@INC contains: /usr/local/lib/perl5/site_perl/5.8.6/darwin-thread-multi-2level /usr/local/lib/perl5/site_perl/5.8.6 /usr/local/lib/perl5/site_perl /System/Library/Perl/5.8.6/darwin-thread-multi-2level /System/Library/Perl/5.8.6 /Library/Perl/5.8.6/darwin-thread-multi-2level /Library/Perl/5.8.6 /Library/Perl /Network/Library/Perl/5.8.6/darwin-thread-multi-2level /Network/Library/Perl/5.8.6 /Network/Library/Perl /System/Library/Perl/Extras/5.8.6/darwin-thread-multi-2level /System/Library/Perl/Extras/5.8.6 /Library/Perl/5.8.1 .) at /usr/bin/git-svn line 2272.
This is because git-svn needs the ReadKey perl module to be able to read the server’s key to encrypt the password before it sends the password to the server. (wouldn’t want to be sending passwords in plain text across the internet would you?). Here is the solution:
Pull up the CPAN teminal:perl -MCPAN -e shell
You may need to set it up if you have never used it…. just use defaults if you are not sure
Once at the cpan prompt install the needed module:cpan> install Term::ReadKey
once it is finished go ahead and quit the cpan terminal and you should be able to run git-svn dcommit and everything should be peachy
Git沖突:commit your changes or stash them before you can merge. 解決辦法
用git pull來更新代碼的時候,遇到了下面的問題:
1 |
error: Your local changes to the following files would be overwritten by merge: |
2 |
xxx/xxx/xxx.php |
3 |
Please, commit your changes or stash them before you can merge. |
4 |
Aborting |
出現這個問題的原因是其他人修改了xxx.php並提交到版本庫中去了,而你本地也修改了xxx.php,這時候你進行git pull操作就好出現沖突了,解決方法,在上面的提示中也說的很明確了。
1、保留本地的修改 的改法
1)直接commit本地的修改
2)通過git stash
1 |
git stash |
2 |
git pull |
3 |
git stash pop |
通過git stash將工作區恢復到上次提交的內容,同時備份本地所做的修改,之后就可以正常git pull了,git pull完成后,執行git stash pop將之前本地做的修改應用到當前工作區。
git stash: 備份當前的工作區的內容,從最近的一次提交中讀取相關內容,讓工作區保證和上次提交的內容一致。同時,將當前的工作區內容保存到Git棧中。
git stash pop: 從Git棧中讀取最近一次保存的內容,恢復工作區的相關內容。由於可能存在多個Stash的內容,所以用棧來管理,pop會從最近的一個stash中讀取內容並恢復。
git stash list: 顯示Git棧內的所有備份,可以利用這個列表來決定從那個地方恢復。
git stash clear: 清空Git棧。此時使用gitg等圖形化工具會發現,原來stash的哪些節點都消失了。
2、放棄本地修改 的改法
1 |
git reset --hard |
2 |
git pull |
Posted in commit, git, 解決, 錯誤.
CentOS 下搭建 Git WEB管理平台
Ruby的安裝
因為CentOS源里的ruby版本太低,我們直接下載源碼進行安裝
安裝之前確認系統中已經安裝了libyaml
沒有的話直接下載源碼安裝
wget http://pyyaml.org/download/libyaml/yaml-0.1.tar.gz
tar zxvf yaml-0.1.tar.gz
cd yaml-0.1
./configure
make && make install
下載ruby源碼
http://ruby.taobao.org/mirrors/ruby/ruby-1.9-stable.tar.gz
安裝
tar zxvf ruby-1.9-stable.tar.gz
cd ruby-1.9-xxxx/
./configure
make && make install
結束
一般情況下安裝會很順利
Gitolite的安裝
創建專屬用戶
useradd -d /home/git -m git
然后用git身份登錄
su git
進入到HOME目錄
cd ~
下載源碼
直接從Github進行clone
git clone git://github.com/sitaramc/gitolite
進行安裝
mkdir -p $HOME/bin
gitolite/install -to $HOME/bin
如果提示Can’t locate Time/HiRes.pm in @INC的話執行下面的命令進行類庫安裝
perl -MCPAN -e shell
install Time::HiRes
如果提示Can’t locate CPAN.pm in @INC的話先使用yum進行安裝yum install perl-CPAN
將bin加入到PATH變量中
編輯~/.profile添加如下內容
export PATH=$PATH:/home/git/bin
GitLab的安裝
創建專屬用戶
useradd -d /home/gitlab -m -g git gitlab
切換至gitlab並進入HOME目錄
依賴的Gems (root身份安裝)
gem install resque
gem install charlock_holmes –version ‘0.6.9’
charlock_holmes 會依賴libicu 可以直接yum安裝yum install libicu-devel
如果提示cannot load such file — zlib需要安裝zlib庫
yum install zlib-devel
# 安裝ruby自帶的zlib.so
cd ruby-1.9-xxxx/ext/zlib
ruby ./extconf.rb
make && make install
下載源碼
git clone git://github.com/gitlabhq/gitlabhq server
站點信息配置
cp server/config/gitlab.yml.example server/config/gitlab.yml
cp server/config/unicorn.rb.example server/config/unicorn.rb
因為我們釋放到了server目錄下,需要修改unicorn.rb將第一行的默認目錄修改下
創建satellites目錄
mkdir gitlab-satellites
數據庫配置
cp server/config/database.yml.mysql server/config/database.yml
Redis配置(一般不需要)
cp server/config/resque.yml.example server/config/resque.yml
進行產品發布
cd ~/server
bundle install –deployment –without development test postgres
找不到bundle的時候可以執行gem install bundler安裝
配置Git
git config –global user.name “GitLab”
git config –global user.email “gitlab@localhost”
配置GitLab的Hooks
# root 權限運行
mkdir -p /home/git/.gitolite/hooks/common
cp /home/gitlab/server/lib/hooks/post-receive /home/git/.gitolite/hooks/common/post-receive
chown git:git -R /home/git/.gitolite
創建用戶(gitlab)的SSH公匙並導入到gitolite中
執行前確定/home/git/.gitolite/logs目錄存在,否則導入key時會報錯
FATAL: errors found but logfile could not be created
FATAL: /home/git/.gitolite/logs/gitolite-2013-02.log: No such file or directory
FATAL: cli gitolite setup -pk /home/git/gitlab.pub
su gitlab
ssh-keygen -t rsa
cp ~/.ssh/id_rsa.pub /home/git/gitlab.pub
chmod 0444 /home/git/gitlab.pub
su git
~/bin/gitolite setup -pk ~/gitlab.pub
關於傳遞了公鑰后依然會要求輸入密碼的情況說明/ssh-keygen后自動驗證無效
如果你無法自動驗證的話先嘗試將/home/git目錄權限設置為755
如果正常了的話就不用看下面這兩條了
使用gitolite的setup命令導入key的時候會在~/.ssh/authorized_keys中添加自定義的command命令,導致/var/log/secure中查看不到ssh自動驗證的錯誤信息(刪除后再嘗試即可)
執行上面的步驟后如果在secure日志中發現Authentication refused: bad ownership or modes for directory /home/git的話需要把git目錄權限設置為755
初始化數據庫
執行下面的命令之前需要配置了正確的數據庫信息並開啟了Redis
需要/home/git目錄權限為770
需要/home/git/repositories目錄權限為770(沒有的話新創建一個)
執行
cd ~/server
bundle exec rake gitlab:setup RAILS_ENV=production
TMD終於好了,讓我們來檢查下gitlab的狀態吧
cd ~/server
# 查看環境信息
bundle exec rake gitlab:env:info RAILS_ENV=production
# 檢查組件依賴(全綠色的話就過了)
bundle exec rake gitlab:check RAILS_ENV=production
添加管理腳本
從https://raw.github.com/gitlabhq/gitlab-recipes/4-1-stable/init.d/gitlab下載腳本到/etc/init.d/gitlab
然后chmod +x /etc/init.d/gitlab給上執行權限
最后chkconfig –add gitlab加到service列表中,然后chkconfig gitlab on開啟自啟動
安裝結束
使用service gitlab start即可啟動gitlab進程了
如何訪問gitlab的web頁面?
gitlab默認是使用的unix socket訪問,需要nginx進行轉發,配置文件在這里https://raw.github.com/gitlabhq/gitlab-recipes/4-1-stable/nginx/gitlab
不過我們可以修改unicorn.rb來使用TCP方式訪問
修改server/config/unicorn.rb找到listen字段將后面的內容修改成
listen 80
即可
訪問web后默認帳號為admin@local.host密碼為5iveL!fe
一些錯誤的解決方法
如果/home/gitlab/server/log/githost.log中出現error
ERROR -> Gitolite error -> error: cannot run hooks/post-receive: No such file or directory
並且切換到git用戶后執行env -i redis-cli報錯
解決方法
ln -s /usr/local/bin/redis-cli /usr/bin/
ERROR -> Gitolite error -> remote: FATAL: git config ‘core.sharedRepository’ not allowed
解決方法
編輯/home/git/.gitolite.rc找到GIT_CONFIG_KEYS將后面的內容修改成’.*’,修改后為GIT_CONFIG_KEYS => ‘.*’
加快 git clone 速度的方法
git clone 可以不用全部下載,只下載當前的 commit 版本,
1 |
git clone git://git.aikaiyuan.com/aikaiyuan.git. --depth 1 |
也就是指定克隆深度為 1。
當然,通過這樣下載的代碼就不能進行管理、提交、修改等等。
Posted in git.
使用bash從SVN和Git中獲取順序版本號,Windows 下 Git 客戶端的選擇
在進行自動部署的時候,經常需要用腳本獲取程序的最新版本號,下面是我的兩個解決方案。
for SVN
# 獲取XML版本的svn信息,這樣可以避免不同語言的問題 __xml=`svn info –xml –incremental` # 我們可以獲取到2個版本號,一個是最新版本庫版本號,一個是自己的提交版本號。刪除自己提交的版本號。 __revision=`echo “$__xml”|sed ‘/revision/!d’|sed ‘$d’` # 提取出版本號的數字部分 echo $__revision|sed ‘s/revision=”([0-9]+)”>?/1/’
# 獲取XML版本的svn信息,這樣可以避免不同語言的問題
__xml=`svn info –xml –incremental`
# 我們可以獲取到2個版本號,一個是最新版本庫版本號,一個是自己的提交版本號。刪除自己提交的版本號。
__revision=`echo “$__xml”|sed ‘/revision/!d’|sed ‘$d’`
# 提取出版本號的數字部分
echo $__revision|sed ‘s/revision=”([0-9]+)”>?/1/’
for Git
Git采用的是SHA散列碼作為版本號,因此它沒有順序的版本號。但我們可以通過統計Git版本庫的提交次數來獲得一個順序版本號。
# 基准版本號默認是1,可以通過傳遞一個參數修改 get_version() { local __base=${1:-1} echo $((`git rev-list –all|wc -l` + $__base)) } get_version 7000
# 基准版本號默認是1,可以通過傳遞一個參數修改
get_version()
{
local __base=${1:-1}
echo $((`git rev-list –all|wc -l` + $__base))
}
get_version 7000
這個版本對網上搜到的那個被普遍轉載的版本做了簡化和調整。網上那個版本寫得比較復雜,例如awk的使用沒有必要,而且要統計所有提交,應該用 git rev-list –all 參數,而不是用 git rev-list HEAD。
本文鏈接:http://zengrong.net/post/1798.htm
Windows 下 Git 客戶端的選擇,TortoiseGit(烏龜git)保存用戶名密碼的方法:
windows下比較比較好用的git客戶端有2種:
1. msysgit + TortoiseGit(烏龜git)
2. GitHub for Windows
github的windows版也用過一段時間,但還是不太習慣。所以目前仍然青睞與msysgit+烏龜git的組合。TortoiseGit在提交時總數會提示你輸入用戶名密碼,非常麻煩。解決方案如下:
方法一:
設置 -> git 編輯本地 .git/config 增加
[credential]
helper = store
保存,輸入一次密碼后第二次就會記住密碼了
方法二:
1. Windows中添加一個HOME環境變量,值為%USERPROFILE%
2. 在“開始>運行”中打開%Home%,新建一個名為“_netrc”的文件
3. 用記事本打開_netrc文件,輸入Git服務器名、用戶名、密碼,並保存:
machine github.com #git服務器名稱
login user #git帳號
password pwd #git密碼
在windows上建_netrc
copy con _netrc #創建_netrc文件
#依次輸入以下3行:
machine github.com #git服務器名稱
login username #git帳號
password password #git密碼
在最后一行后輸入ctrl+z,文件會自動保存並退出
再次在git上提交時就不用重復輸入用戶名密碼了
Git 取消跟蹤已版本控制的文件
Git 是一個很好的版本控制工具,當然駕馭起來相比 SVN 要稍微復雜一些。初入 Git,難免有一些問題。比如我們不小心將某個文件加入了版本控制,但是突然又不想繼續跟蹤控制這個文件了,怎么辦呢?
其實方法也是很簡單的。使用git update-index 即可。
不想繼續追蹤某個文件
1 |
git update-index --assume-unchanged your_file_path |
如果想再次繼續跟蹤某個文件
1 |
git update-index --no-assume-unchanged your_file_path |
Posted in git.
Git、Gitosis版本控制詳細配置
Git是分布式的版本控制系統,實際上是不需要固定的服務器的,Git與svn的最大區別是,它的使用流程不需要聯機,可以先將對代碼的修改,評論,保存在本機。等上網之后,再實時推送過去。同時它創建分支與合並分支更容易,推送速度也更快。
Gitosis則是方便通過Git與ssh架設中央服務器的軟件。
一、Linux下git安裝配置
1、yum安裝
yum install git git-svn git-email git-gui gitk
2、源碼安裝
下載最新git-1.8.0.tar.gz ,執行下面命令
tar -xzf git-1.8.0.tar.gz
cd git-1.8.0
./configure -prefix=/usr/local/git –with-curl –with-expat
make && make install
修改/etc/profile,在PATH中加入git路徑,並執行source /etc/profile
GIT_HOME=/usr/local/git
PATH=$PATH:$GIT_HOME/bin:$GIT_HOME/libexec/git-core
export PATH GIT_HOME
確認是否安裝成功
git –version
git version 1.8.0
可能碰見的錯誤:
a、GIT錯誤
usr/local/git/share/locale’
Can’t locate ExtUtils/MakeMaker.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at Makefile.PL line 3.
BEGIN failed–compilation aborted at Makefile.PL line 3.
解決:yum install perl-ExtUtils-MakeMaker
b、tclsh failed; using unoptimized loading
MSGFMT po/de.msg make[1]: *** [po/de.msg] Error 127
解決:yum install tcl
c、/bin/sh: msgfmt: command not found
make: *** [po/build/locale/da/LC_MESSAGES/git.mo] Error 127
解決:yum install gettext-devel
d、git clone時候提示fatal: Unable to find remote helper for ‘https’
解決:yum install libcurl-devel
3、復制命令補全腳本 並執行腳本
cp contrib/completion/git-completion.bash /etc/
sh /etc/git-completion.bash
試試輸入”git li”, 再按下 TAB 就可以自動提示補全。
二、Windows下git使用
windows下有下個幾個git客戶端,我選擇的是Cygwin。
Cygwin http://www.cygwin.com/ 安裝參考 cygwin安裝說明
msysGit http://msysgit.github.com/
TortoiseGit http://code.google.com/p/tortoisegit/
三、git使用說明
1、添加git配置信息
git config –global user.name “Steven”
git config –global user.email seyo816@email.com
Git的配置信息分為全局和項目兩種,上面命令中帶了“–global”參數,這就意味是在進行全局配置,它會影響本機上的每個一個Git項目。
查看全局配置信息,可以看到我們配置的用戶名和郵箱。
$ cat ~/.gitconfig
[user]
name = Steven
email = seyo816@email.com
2、創建本地倉儲
#創建版本庫目錄
mkdir -p gitdemo
cd gitdemo
echo “README” > readme.txt
#初始化版本庫
git init
Initialized empty Git repository in /data/gitdemo/.git/
#把前目錄下的所有文件全部添加到暫存區
git add .
#創建提交
git commit -m ‘init’
[master (root-commit) 55f9dbb] init
1 file changed, 1 insertion(+)
create mode 100644 readme.txt
#查看git文件信息
git show
commit 55f9dbb575f536702eb02a09fe65d8d060769380
Author: Steven <seyo816@email.com>
Date: Thu Nov 15 23:11:55 2012 +0800init
diff –git a/readme.txt b/readme.txt
new file mode 100644
index 0000000..6372732
— /dev/null
+++ b/readme.txt
@@ -0,0 +1 @@
+“README”
3、git基本操作
#clone一個項目
git clone ssh://git@lifeba_vps:bqueue.git
添加文件到版本庫
git add test2.txt
git commit -m “add test2.txt”
git push獲取最新代碼
git pull
git fetch git路徑更新文件提交
git commit -a 或 git commit -a -e 提交全部修改文件,並調用vim編輯提交日志。
git push查看狀態
git status #查看版本庫的狀態。可以得知哪些文件發生了變化,哪些文件還沒有添加到git庫中等等。 建議每次commit前都要通過該命令確認庫狀態。
查看未版本控制
git clean -dxf 用於清除未跟蹤文件。
git clean -dnf 可以顯示需要刪除的文件,但不包括被.gitignore忽略的。沖突解決
git rebase
git add -u 表示把所有已track的文件的新的修改加入緩存,但不加入新的文件。
git rebase –continue #有沖突繼續解決,重復這這些步驟,直到rebase完成。
如果中間遇到某個補丁不需要應用,可以用下面命令忽略:
git rebase –skip
如果想回到rebase執行之前的狀態,可以執行:
git rebase –abort注:rebase之后,不需要執行commit,也不存在新的修改需要提交,都是git自動完成。
四、gitosis安裝和配置
1、gitosis安裝
cd /disk/src
git clone https://github.com/res0nat0r/gitosis.git
cd gitosis/
python setup.py install
2、gitosis配置
a、
因為要涉及到ssh操作,使用必須建個單獨的用戶,不能使用超級用戶。
#創建目錄
mkdir /data/git
#添加git用戶,並且制定到/data/git目錄下
useradd
-r
-s /bin/sh
-c ‘git version control’
-d /data/git
git
#對git目錄設置用戶和組為git
chown git:git /data/git
#設置成功后,執行ll看到用戶和組都是git
ll
drwxr-xr-x 2 git git 4096 Nov 16 00:41 git
b、
在本機的客戶端上面生成ssh的key,然后上傳到gitosis的服務器上面。
#生成pub文件,將pub文件放置到:/tmp/id_rsa.pub
ssh-keygen -t rsa
gitosis的服務器切換到git用戶:
su – git
然后執行
-sh-4.1$ gitosis-init < /tmp/id_rsa.pub
Initialized empty Git repository in /data/git/repositories/gitosis-admin.git/
Reinitialized existing Git repository in /data/git/repositories/gitosis-admin.git/
注意在root中執行:sudo -H -u git gitosis-init < /tmp/id_rsa.pub ,會出現下面異常,所以切換到git用戶。
File “/usr/local/bin/gitosis-init”, line 8, in <module> 異常。
執行成功后查看key是不是已經設置成功,執行下面命令后可以看到我們提交的id_rsa.pub內容
cat ~/.ssh/authorized_keys
對post-update目錄設置權限
chmod 755 /data/git/repositories/gitosis-admin.git/hooks/post-update
五、本機操作gitosis-admin項目
通過上面的操作后,本機的客戶端已經可以通過ssh訪問到服務器的gitosis-admin項目(本身也是通過git來管理的),這樣可以通過本機的git操作來同步到服務器的gitosis中。
1、Creating new repositories,本地拉下gitosis-admin項目。
git clone git@lifeba_vps:gitosis-admin.git
Cloning into ‘gitosis-admin’…
注意,可能出現下面的錯誤:
Traceback (most recent call last):
File “/usr/local/bin/gitosis-serve”, line 8, in <module>
load_entry_point(‘gitosis==0.2′, ‘console_scripts’, ‘gitosis-serve’)()
File “/usr/local/lib/python2.7/site-packages/gitosis-0.2-py2.7.egg/gitosis/app.py”, line 24, in run
return app.main()
File “/usr/local/lib/python2.7/site-packages/gitosis-0.2-py2.7.egg/gitosis/app.py”, line 38, in main
self.handle_args(parser, cfg, options, args)
File “/usr/local/lib/python2.7/site-packages/gitosis-0.2-py2.7.egg/gitosis/serve.py”, line 213, in handle_args
os.execvp(‘git’, [‘git’, ‘shell’, ‘-c’, newcmd])
File “/usr/local/lib/python2.7/os.py”, line 344, in execvp
_execvpe(file, args)
File “/usr/local/lib/python2.7/os.py”, line 380, in _execvpe
func(fullname, *argrest)
OSError: [Errno 2] No such file or directory
fatal: The remote end hung up unexpectedly
解決方法:在gitosis服務器上面建個軟連接
ln -s /usr/local/git/bin/git /usr/local/bin/git
2、gitosis-admin項目說明
a、文件說明
cd gitosis-admin
Administrator@Steven-PC /cygdrive/e/research/gitosis-admin
$ ls -l
總用量 1
-rw-r–r– 1 Administrator None 93 十一 16 01:49 gitosis.conf
drwxr-xr-x+ 1 Administrator None 0 十一 16 01:49 keydir
gitosis.conf是gitosis的配置文件,用於配置用戶和權限
keydir/是所有組成員的公鑰
我們可以在本地修改配置更改權限,然后push到服務端后,服務器端就立刻生效
b、添加一個其他客戶端ssh支持,這樣其他的客戶端可以訪問到gitosis的對應項目。
先查看現有的配置,下面只有一個gitosis-admin組,members中的Administrator@Steven-PC就是本機客戶端名,writable,表示對gitosis-admin項目有讀寫操作權限。這些都是上面我們通過ssh來配置生成的。
$ cat gitosis.conf
[gitosis][group gitosis-admin]
members = Administrator@Steven-PC
writable = gitosis-admin
c、現在我們往gitosis上面提交一個bqueue項目。
先定義賬號權限,我們在后面自定義一個組bqueue,同樣指定Administrator@Steven-PC可以讀寫bqueue項目。
[group bqueue]
members = Administrator@Steven-PC
writable = bqueue
然后push到服務器,將本地的配置push到gitosis服務器上面。
git commit -a -m “Allow Steven write access to bqueue”
[master 9b1959b] Allow Steven write access to bqueue
1 files changed, 4 insertions(+), 0 deletions(-)$ git push
Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 378 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@173.230.147.166:gitosis-admin.git
507d7cf..9b1959b master -> master
上面的操作就更新了服務端的權限。
d、push本地的bqueue項目到gitosis服務器上面。
完成了上面的權限設置后,就可以通過下面命令,將本地的bqueue項目提交給gitosis服務器。
git remote add origin ssh://git@lifeba_vps/bqueue.git
git push origin master
Initialized empty Git repository in /data/git/repositories/bqueue.git/
Counting objects: 192, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (181/181), done.
Writing objects: 100% (192/192), 921.81 KiB, done.
Total 192 (delta 54), reused 0 (delta 0)
To ssh://git@lifeba_vps/bqueue.git
* [new branch] master -> master
六、訪問bqueue項目
上面我們已經提交了一個bqueue項目到gitosis服務器,如何讓其他用戶訪問並操作該項目呢?
首先必須先配置ssh權限,在需要訪問該bqueue項目的客戶端上面,同樣要生成一個ssh的key。
在目標客戶端機上面執行下面命令,將生成id_rsa.pub提交給擁有gitosis-admin控制權限的用戶,這里就是:Administrator@Steven-PC用戶。
#生成ssh的key
ssh-keygen -t rsa
在Administrator@Steven-PC的機子上面做如下操作,先切換到gitosis-admin項目下:
cd keydir/ #將 我們將id_rsa.pub重名為 lifeba@vps.pub ,並放到這里。
git add keydir/lifeba@vps.pub #添加到git緩存中。
修改gitosis.conf 加入lifeba@vps
[group bqueue]
members = Administrator@Steven-PC lifeba@vps
writable = bqueue
提交並推送到gitosis服務器
git commit -a -m “Allow lifeba@vps write access to bqueue”
git push
完成上面的操作后,目標客戶端就可以通過git clone來訪問bqueue項目了。執行下面命令來clone項目。
git clone git@lifeba_vps:bqueue.git
可能出現的錯誤:
1、Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
fatal: Could not read from remote repository.
ssh的權限沒配置好。
2、ERROR:gitosis.serve.main:Repository read access denied
fatal: Could not read from remote repository.
gitosis.conf中的members與keydir中的用戶名不一致,如gitosis中的members = lifeba@vps,但keydir中的公密名卻叫id_rsa.pub
七、git常用命令
git pull –rebase
git rebase –continue
git pull –rebase其實就等於git fetch + git rebasegit diff 查看修改和緩存中的修改信息
git diff cache 查看緩存中的和commit中的修改信息
git branch -a 查看所有分支。
git branch new_branch 創建新的分支。
git branch -d branch 刪除分支。
git checkout branch 切換當前分支。-f參數可以覆蓋未提交內容。
git branch -v
git remote -v
.gitignore 在規則建立之前的就已經在代碼庫中的文件不會受到忽略規則的影響,要移除這些文件,只能輸入git rm filename來移除。
git rm -f *.o 取消跟蹤並在工作目錄中刪除
git rm –cached readme.txt 取消跟蹤不在工作目錄中刪除
git mv file_from file_to 相當於 mv README.txt README $ git rm README.txt $ git add README
git log -p -2 -p 選項展開顯示每次提交的內容差異,用 -2 則僅顯示最近的兩次更新:
git log –stat 簡要顯示
git log –pretty=format:”%h – %an, %ar : %s”
git log –pretty=format:”%h %s” –graph
git log –since=2.weeks
git log –pretty=”%h – %s” –author=gitster –since=”2008-10-01″
–before=”2008-11-01″ –no-merges — t/
git reset HEAD benchmarks.rb 取消已經暫存的文件
git checkout — benchmarks.rb 取消對文件的修改git remote -v 查看現有的遠程倉庫
git remote add pb git://github.com/paulboone/ticgit.git 添加一個遠程倉庫 並用pb命名。
git remote rm paul 刪除遠程倉庫
git remote rename pb paul 重名遠程倉庫 本地也會跟着修改
git remote 查看遠程參考
git remote showgit branch 顯示所有開發分支
git branch experimental 創建新的開發分支
git checkout experimental 切換到”experimental”分支
git merge experimental 合並分支,如果這個兩個分支間的修改沒有沖突(conflict), 那么合並就完成了。如有有沖突,輸入下面的命令就可以查看當前有哪些文件產生了沖突:$ git diff,git commit -a
git branch -d experimental 刪除分支(合並過才刪除)
git branch -D crazy-idea 強制刪除分支
八、參考資料
Git的安裝和配置
http://www.infoq.com/cn/news/2011/02/git-adventures-local-repository
http://scie.nti.st/2007/11/14/hosting-git-repositories-the-easy-and-secure-way
Git服務器Gitosis安裝設置
搭建git服務器及配置gitosis管理用戶權限
使用gitosis來配置管理git服務器端
git使用說明
Git安裝與配置
Git詳解之二:Git基礎
Git下的沖突解決
Posted in git.
Git遠程操作詳解
Git有很多優勢,其中之一就是遠程操作非常簡便。本文詳細介紹5個Git命令,它們的概念和用法,理解了這些內容,你就會完全掌握Git遠程操作。
- git clone
- git remote
- git fetch
- git pull
- git push
本文針對初級用戶,從最簡單的講起,但是需要讀者對Git的基本用法有所了解。同時,本文覆蓋了上面5個命令的幾乎所有的常用用法,所以對於熟練用戶也有參考價值。

一、git clone
遠程操作的第一步,通常是從遠程主機克隆一個版本庫,這時就要用到git clone命令。
1 |
$ git clone <版本庫的網址> |
比如,克隆jQuery的版本庫。
1 |
$ git clone https://github.com/jquery/jquery.git |
該命令會在本地主機生成一個目錄,與遠程主機的版本庫同名。如果要指定不同的目錄名,可以將目錄名作為git clone命令的第二個參數。
1 |
$ git clone <版本庫的網址> <本地目錄名> |
git clone支持多種協議,除了HTTP(s)以外,還支持SSH、Git、本地文件協議等,下面是一些例子。
$ git clone http[s]://example.com/path/to/repo.git/ |
$ git clone ssh://example.com/path/to/repo.git/ |
$ git clone git://example.com/path/to/repo.git/ |
$ git clone /<span id="11_nwp" style="width: auto; height: auto; float: none;"><a id="11_nwl" href="http://cpro.baidu.com/cpro/ui/uijs.php?rs=1&u=http%3A%2F%2Fwww%2Eaikaiyuan%2Ecom%2Fcategory%2Fgit&p=baidu&c=news&n=10&t=tpclicked3_hc&q=selboo1_cpr&k=opt&k0=opt&k1=server&k2=%CA%FD%BE%DD%BF%E2&k3=postgresql&k4=access&k5=%D4%B4%C2%EB&sid=88277fa911188c36&ch=0&tu=u1896194&jk=d18d0685ae2993c8&cf=29&fv=14&stid=9&urlid=0&luki=4&seller_id=1&di=128" target="_blank" mpid="11" style="text-decoration: none;"><span style="color:#0000ff;font-size:13px;width:auto;height:auto;float:none;">opt</span></a></span>/git/project.git |
$ git clone file:///opt/git/project.git |
$ git clone ftp[s]://example.com/path/to/repo.git/ |
$ git clone rsync://example.com/path/to/repo.git/ |
SSH協議還有另一種寫法。
1 |
$ git clone [user@]example.com:path/to/repo.git/ |
通常來說,Git協議下載速度最快,SSH協議用於需要用戶認證的場合。各種協議優劣的詳細討論請參考官方文檔。
二、git remote
為了便於管理,Git要求每個遠程主機都必須指定一個主機名。git remote命令就用於管理主機名。
不帶選項的時候,git remote命令列出所有遠程主機。
1 |
$ git remote |
2 |
origin |
使用-v選項,可以參看遠程主機的網址。
1 |
$ git remote -v |
2 |
origin git@github.com:jquery/jquery.git (fetch) |
3 |
origin git@github.com:jquery/jquery.git (push) |
上面命令表示,當前只有一台遠程主機,叫做origin,以及它的網址。
克隆版本庫的時候,所使用的遠程主機自動被Git命名為origin。如果想用其他的主機名,需要用git clone命令的-o選項指定。
1 |
$ git clone -o jQuery https://github.com/jquery/jquery.git |
2 |
$ git remote |
3 |
jQuery |
上面命令表示,克隆的時候,指定遠程主機叫做jQuery。
git remote show命令加上主機名,可以查看該主機的詳細信息。
1 |
$ git remote show <主機名> |
git remote add命令用於添加遠程主機。
1 |
$ git remote add <主機名> <網址> |
git remote rm命令用於刪除遠程主機。
1 |
$ git remote rm <主機名> |
git remote rename命令用於遠程主機的改名。
1 |
$ git remote rename <原主機名> <新主機名> |
三、git fetch
一旦遠程主機的版本庫有了更新(Git術語叫做commit),需要將這些更新取回本地,這時就要用到git fetch命令。
1 |
$ git fetch <遠程主機名> |
上面命令將某個遠程主機的更新,全部取回本地。
默認情況下,git fetch取回所有分支(branch)的更新。如果只想取回特定分支的更新,可以指定分支名。
1 |
$ git fetch <遠程主機名> <分支名> |
比如,取回origin主機的master分支。
1 |
$ git fetch origin master |
所取回的更新,在本地主機上要用”遠程主機名/分支名”的形式讀取。比如origin主機的master,就要用origin/master讀取。
git branch命令的-r選項,可以用來查看遠程分支,-a選項查看所有分支。
1 |
$ git branch -r |
2 |
origin/<span id="10_nwp" style="width: auto; height: auto; float: none;"><a id="10_nwl" href="http://cpro.baidu.com/cpro/ui/uijs.php?rs=1&u=http%3A%2F%2Fwww%2Eaikaiyuan%2Ecom%2Fcategory%2Fgit&p=baidu&c=news&n=10&t=tpclicked3_hc&q=selboo1_cpr&k=master&k0=master&k1=%BF%AA%D4%B4&k2=mysql&k3=opt&k4=server&k5=%CA%FD%BE%DD%BF%E2&sid=88277fa911188c36&ch=0&tu=u1896194&jk=d18d0685ae2993c8&cf=29&fv=14&stid=9&urlid=0&luki=1&seller_id=1&di=128" target="_blank" mpid="10" style="text-decoration: none;"><span style="color:#0000ff;font-size:13px;width:auto;height:auto;float:none;">master</span></a></span> |
3 |
4 |
$ git branch -a |
5 |
* master |
6 |
remotes/origin/master |
上面命令表示,本地主機的當前分支是master,遠程分支是origin/master。
取回遠程主機的更新以后,可以在它的基礎上,使用git checkout命令創建一個新的分支。
1 |
$ git checkout -b newBrach origin/master |
上面命令表示,在origin/master的基礎上,創建一個新分支。
此外,也可以使用git merge命令或者git rebase命令,在本地分支上合並遠程分支。
1 |
$ git merge origin/master |
2 |
# 或者 |
3 |
$ git rebase origin/master |
上面命令表示在當前分支上,合並origin/master。
四、git pull
git pull命令的作用是,取回遠程主機某個分支的更新,再與本地的指定分支合並。它的完整格式稍稍有點復雜。
1 |
$ git pull <遠程主機名> <遠程分支名>:<本地分支名> |
比如,取回origin主機的next分支,與本地的master分支合並,需要寫成下面這樣。
1 |
$ git pull origin next:master |
如果遠程分支是與當前分支合並,則冒號后面的部分可以省略。
1 |
$ git pull origin next |
上面命令表示,取回origin/next分支,再與當前分支合並。實質上,這等同於先做git fetch,再做git merge。
1 |
$ git fetch origin |
2 |
$ git merge origin/next |
在某些場合,Git會自動在本地分支與遠程分支之間,建立一種追蹤關系(tracking)。比如,在git clone的時候,所有本地分支默認與遠程主機的同名分支,建立追蹤關系,也就是說,本地的master分支自動”追蹤”origin/master分支。
Git也允許手動建立追蹤關系。
1 |
git branch --set-upstream master origin/next |
上面命令指定master分支追蹤origin/next分支。
如果當前分支與遠程分支存在追蹤關系,git pull就可以省略遠程分支名。
1 |
$ git pull origin |
上面命令表示,本地的當前分支自動與對應的origin主機”追蹤分支”(remote-tracking branch)進行合並。
如果當前分支只有一個追蹤分支,連遠程主機名都可以省略。
1 |
$ git pull |
上面命令表示,當前分支自動與唯一一個追蹤分支進行合並。
如果合並需要采用rebase模式,可以使用–rebase選項。
1 |
$ git pull --rebase <遠程主機名> <遠程分支名>:<本地分支名> |
五、git push
git push命令用於將本地分支的更新,推送到遠程主機。它的格式與git pull命令相仿。
1 |
$ git push <遠程主機名> <本地分支名>:<遠程分支名> |
注意,分支推送順序的寫法是<來源地>:<目的地>,所以git pull是<遠程分支>:<本地分支>,而git push是<本地分支>:<遠程分支>。
如果省略遠程分支名,則表示將本地分支推送與之存在”追蹤關系”的遠程分支(通常兩者同名),如果該遠程分支不存在,則會被新建。
1 |
$ git push origin master |
上面命令表示,將本地的master分支推送到origin主機的master分支。如果后者不存在,則會被新建。
如果省略本地分支名,則表示刪除指定的遠程分支,因為這等同於推送一個空的本地分支到遠程分支。
1 |
$ git push origin :master |
2 |
# 等同於 |
3 |
$ git push origin --delete master |
上面命令表示刪除origin主機的master分支。
如果當前分支與遠程分支之間存在追蹤關系,則本地分支和遠程分支都可以省略。
1 |
$ git push origin |
上面命令表示,將當前分支推送到origin主機的對應分支。
如果當前分支只有一個追蹤分支,那么主機名都可以省略。
1 |
$ git push |
如果當前分支與多個主機存在追蹤關系,則可以使用-u選項指定一個默認主機,這樣后面就可以不加任何參數使用git push。
1 |
$ git push -u origin master |
上面命令將本地的master分支推送到origin主機,同時指定origin為默認主機,后面就可以不加任何參數使用git push了。
不帶任何參數的git push,默認只推送當前分支,這叫做simple方式。此外,還有一種matching方式,會推送所有有對應的遠程分支的本地分支。Git 2.0版本之前,默認采用matching方法,現在改為默認采用simple方式。如果要修改這個設置,可以采用git config命令。
1 |
$ git config --global push.default matching |
2 |
# 或者 |
3 |
$ git config --global push.default simple |
還有一種情況,就是不管是否存在對應的遠程分支,將本地的所有分支都推送到遠程主機,這時需要使用–all選項。
1 |
$ git push --all origin |
上面命令表示,將所有本地分支都推送到origin主機。
如果遠程主機的版本比本地版本更新,推送時Git會報錯,要求先在本地做git pull合並差異,然后再推送到遠程主機。這時,如果你一定要推送,可以使用–force選項。
1 |
$ git push --force origin |
上面命令使用–force選項,結果導致在遠程主機產生一個”非直進式”的合並(non-fast-forward merge)。除非你很確定要這樣做,否則應該盡量避免使用–force選項。
最后,git push不會推送標簽(tag),除非使用–tags選項。
1 |
$ git push origin --tags |
Posted in git.
GitLab 7.0基於Git 的代碼托管系統
GitLab 7.0 發布了,改進內容包括:
以下內容來自 ustc
Gitlab7.0放棄了對ruby-1.9.3的支持,最低版本為ruby-2.0.0。由於官方安裝說明指出:使用rvm等自動工具安裝ruby,可能導致ssh操作倉庫異常,因此手動編譯了ruby-2.0.0-p481。
在安裝編譯環境和ruby依賴時發現apt-get中許多軟件包的依賴關系有問題,經過修復解決了一部分依賴問題,到目前為止仍然有部分包的依賴關系不正確。
由於重裝了ruby-gem,因此需要重裝Gitlab所需的所有gems
安裝rubygem:mysql時,提示:
unable to convert “xE0″ from ASCII-8BIT to UTF-8 for lib/mysql2/mysql2.so, skipping
這是由於locale設置錯誤引起的
解決辦法:
export LANGUAGE=en_US.UTF-8
export.UTF-8
export LC_ALL=en_US.UTF-8
另外,為nginx配置增加了X-Forwarded-Forh和X-Frame-Options字段.
Gitlab官方升級教程存在缺陷,本次的升級腳本添加了service啟動腳本的替換。
目前遺留問題:
- Gitlab給出了nginx的https配置模板,但是,我為當前配置添加X-Forwarded-Proto字段時報錯“could not build the proxy_headers_hash, you should increase either proxy_headers_hash_max_size: 512 or proxy_headers_hash_bucket_size: 64”
- Gitlab的主配置文件config.yml過期,之前升級版本時都沒有注意更新,導致最新版本的配置和當前配置相差較大,合並較困難。幸運的是,這暫時還沒有引發問題。
7.0主要特性:
- 受保護的分支不能被刪除
- 開發人員可以使用UI清除普通分支
- 增強對第三方CI工具的支持
- 通過向markdown文本拖動圖片,即可將圖片上傳並插入到markdown中(贊)
- 允許對huge push設置提醒
- 支持LDAP過濾器
- 移除wall功能
- 增強對移動客戶端的支持
- 其他邏輯改進
- 其他安全性改進
- 其他UI改進
GitLab是一個利用 Ruby on Rails 開發的開源應用程序,實現一個自托管的Git項目倉庫,可通過Web界面進行訪問公開的或者私人項目。
它擁有與Github類似的功能,能夠瀏覽源代碼,管理缺陷和注釋。可以管理團隊對倉庫的訪問,它非常易於瀏覽提交過的版本並提供一個文件歷史庫。團隊成員可以利用內置的簡單聊天程序(Wall)進行交流。它還提供一個代碼片段收集功能可以輕松實現代碼復用,便於日后有需要的時候進行查找。
開源中國的 http://git.oschina.net 就是基於 Gitlab 搭建。
下載地址:
https://github.com/gitlabhq/gitlabhq/releases/tag/v7.0.0
linux git 客戶端 smartgit
本機裝了雙系統centos6.5,在centos下裝了一套開發環境,發現linux下的git圖形客戶端好少,能用的更少。本想裝一下gitg的,發現gitg要求的依賴包好新,centos基本上不能滿足,如果非要用的話,要手動更新好多包,太麻煩。在centos下,推薦使用smartgit。
一,下載linux版smartgit
下載地址:http://www.syntevo.com/smartgithg/download
二,安裝git
- # yum install git
三,生成公鑰和私鑰
- # ssh-keygen -t rsa -C “你的郵箱”
- [zhangying@localhost .ssh]$ pwd //默認是在~/.ssh目錄下
- /home/zhangying/.ssh
- [zhangying@localhost .ssh]$ ls
- id_rsa id_rsa.pub //.pub是公鑰,沒后綴的是私鑰
四,把公鑰上傳到git的服務器
把.pub的文件傳到git的服務端,或者是把.pub的內容放到服務端,這要看你服務端用的是什么管理工具了。
五,啟動smartgit
啟動很簡單,解壓后運行一個/home/zhangying/download/smartgithg-generic-5_0_9/bin/smartgithg.sh就行了。
在這里要注意有二點:
1,要用root運行
2,在添加私鑰的時候,只能識別openssh的方式。windows下的.ppk文件,smartgit根本無法識別。
看一下效果圖:

Posted in git.
git項目同時支持多個遠端倉庫
為了防止github被牆,最好在國內的托管商做一個備份,這就需要同時提交到多個遠端倉庫,例如一個open source項目同時要提交csdn和github,url分別是
- git@github.com:lutaf/auto-complete.git
- git@code.csdn.net:lutaf/autocomplete.git
方法很簡單,一共分4步
第一步:添加remote信息
git remote gh git@github.com:lutaf/auto-complete.gitgit remote cn git@code.csdn.net:lutaf/autocomplete.git
第二步:為每個倉庫建立單獨的分支
git checkout -b github...git checkout -b csdn
第三步:在各自分支上完成開發,並提交
第四步:把本地分支推送到遠端倉庫的master分支
git checkout csdngit push cn csdn:master
第四步很關鍵,一定是要推送到遠端倉庫的master分支
Posted in git.
svn 遷移到git下全過程
git的出現,讓svn深受打擊,大家紛紛轉戰git。沒錯,我也移情別戀了,一下就描述一下拋棄svn,迷上git的過程吧
簡單粗暴,命令如下:
git svn clone https://localhost:8443/svn/www/ –no-metadata –trunk=trunk www
參數說明:
no metadata 參數是阻止git 導出svn包含的附加信息,這樣提交到Git的記錄就會顯得很“干凈”
trunk 主分支
www 創建的git項目名稱
執行過程可能會有svn帳戶的輸入,反正就用戶名跟密碼吧
2.代碼克隆下來之后,這已經是一個git下checkout的項目了,只是他還沒有代碼庫源,簡單的說就是他還沒有個git下固定的家(他生母是svn,得給他找個繼母),因此要先在你的github,或者你們公司內部搭建的git平台,創建一個 屬於www項目的git庫,當然也可以自己本地創建,這里就不詳細說了,等下說到代碼部署會說到。
比如代碼庫如下:
git@gitlab.xxx.com:second/test.git
為了證明www確實還沒有新媽,你可以用命令:
git remote -v 查看一下是否有源,執行完很明顯,什么都沒顯示
接下來就是把你的www庫領回test.git這個媽的家里,命令如下:
git remote add git@gitlab.xxx.com:second/test.git
執行完之后,你可以再執行一次git remote -v 你會發現如下:
origin剛才谷歌翻譯了一下,是起源的意思,其實在執行git remote add 原本是需要給源取個名字的,比如發布源 release
就需要這樣輸入git remote add release git@gitlab.xxx.com:second/test.git,因為www還沒有源,所以添加的就變成默認的源,也就是起源了,因此省略了 origin
到這里,已經完成了認識新媽的過程,接下來干嘛,沒錯,所有代碼領回家,命令如下
git push
代碼從svn 到git 就算完成了。
其實在這個過程里似乎漏了一步,沒有在git下創建分支,git branch -a 查看一下,發現已經自動創建了默認主分支master
案例:
1.物理環境
Git-server Centos5.8 192.168.1.245
Svn-server Centos5.8 192.168.1.108
2.建立SVN用戶到git用戶的映射文件,文件格式如下:
1 |
cat /tmp/userinfo.txt |
2 |
david=sfzhang<shifeng_zhang88@163.com> |
3 |
yanni=yanni<yanni_liu88@163.com> |
3.通過git svn clone克隆一個git版本庫,SVN里面包含trunk,branches和tags。
1 |
git svn clone svn://192.168.1.108:9999/yanzi/ --no-metadata --authors-file=userinfo.txt --trunk=trunkmobile --tags=tags --branches=branches --ignore-refs=refs/remotes/yanzi-.* yanzi |
- 參數–no-metadata表示阻止git導出SVN包含的一些無用信息
- 參數–authors-file表示SVN賬號映射到git賬號文件,所有svn作者都要做映射
- 參數–trunkmobile表示主開發項目
- 參數–branches表示分支項目,
--ignore-refs表示不包含后面的分支項目 - 參數yanzi表示git項目名稱
4.通過git log 查看項目提交的歷史記錄,包括作者,日照,和提交注釋信息等。
1 |
cd yanzi |
2 |
git log |
3 |
commit 3c4907782804096ea3fa3fb5419dcce610e56f1f |
4 |
Author: david <shifeng_zhang88@163.com> |
5 |
Date: Fri May 10 10:27:50 2013 +0000 |
5.在git版本庫里面tag都是branches(分支),首先列出當前所有的分支。
1 |
cd yanzi |
2 |
git branch -r |
3 |
tags/mobile_1.0.0 |
4 |
tags/mobile_1.0.1 |
5 |
trunk |
6 |
yanziios1.0.1-build-2223-branch-002 |
6.手動將branches分支轉換為tags。
1 |
git tag mobile_1.0.0 tags/mobile_1.0.0 |
2 |
git tag mobile_1.0.1 tags/mobile_1.0.1 |
7.將多余的branches刪除掉
1 |
git branch -r -d tags/mobile_1.0.0 |
2 |
Deleted remote branch tags/mobile_1.0.0 (was d50002b). |
3 |
git branch -r -d tags/mobile_1.0.1 |
4 |
Deleted remote branch tags/mobile_1.0.1 (was e7b78a2). |
8.再次列出當前的所有分支。
1 |
git branch -r |
2 |
trunk |
3 |
yanziios1.0.1-build-2223-branch-002 |
9.建立git倉庫並初始化版本庫。
1 |
mkdir -p /data/gitdata/yanziios.git |
2 |
cd /data/gitdata/yanziios.git/ |
3 |
git init --bare |
4 |
Initialized empty Git repository in /data/gitdata/yanziios.git/ |
10.將yanziios.git的屬主修改為git用戶。
01 |
chown git yanziios.git -R |
02 |
ls -l yanziios.git/ |
03 |
total 64 |
04 |
drwxr-xr-x 2 git root 4096 May 22 12:25 branches |
05 |
-rw-r--r-- 1 git root 66 May 22 12:25 config |
06 |
-rw-r--r-- 1 git root 73 May 22 12:25 description |
07 |
-rw-r--r-- 1 git root 23 May 22 12:25 HEAD |
08 |
drwxr-xr-x 2 git root 4096 May 22 12:25 hooks |
09 |
drwxr-xr-x 2 git root 4096 May 22 12:25 info |
10 |
drwxr-xr-x 4 git root 4096 May 22 12:25 objects |
11 |
drwxr-xr-x 4 git root 4096 May 22 12:25 refs |
11.添加遠程git服務器地址
1 |
git remote add origin git@192.168.1.245:/data/gitdata/yanziios.git |
12.用git push命令推送全部的分支和標簽信息到git服務器上面。
1 |
git push origin <span id="0_nwp" style="width: auto; height: auto; float: none;"><a id="0_nwl" href="http://cpro.baidu.com/cpro/ui/uijs.php?rs=1&u=http%3A%2F%2Fwww%2Eaikaiyuan%2Ecom%2Fcategory%2Fgit&p=baidu&c=news&n=10&t=tpclicked3_hc&q=selboo1_cpr&k=master&k0=master&k1=%BF%AA%D4%B4&k2=mysql&k3=opt&k4=server&k5=%CA%FD%BE%DD%BF%E2&sid=88277fa911188c36&ch=0&tu=u1896194&jk=d18d0685ae2993c8&cf=29&fv=14&stid=9&urlid=0&luki=1&seller_id=1&di=128" target="_blank" mpid="0" style="text-decoration: none;"><span style="color:#0000ff;font-size:13px;width:auto;height:auto;float:none;">master</span></a></span> --tags |
13.SVN遷移到Git測試,在客戶端用SourceTree工具克隆一個Git服務端倉庫yanziios.git
14.在SourceTree圖形界面里面可以看到git用戶提交的Graph信息,描述信息(Description),日期,作者和版本號等信息。
總結:
- 在運行git svn clone svn: 命令時出現下面的錯誤:Can‘t locate SVN/Core.pm in @INC (@INC contains: /usr/local/git/lib/perl5/site_perl/5.8.,需要安裝subversion-perl軟件包。
- 在運行git pull git@192.168.1.245:/data/gitdata/yanziios.git時出現下面錯誤:Can’t locate Term/ReadKey.pm in @INC(@INC contains:需要運行下面命令:
Pull up the CPAN teminal:
perl -MCPAN -e shell
Once at the cpan prompt install the needed module:
cpan> install Term::ReadKey
- 需要在本機用ssh-keygen -t rsa -C your_email_name生成KEY認證文件,然后把公鑰id_rsa.pub追加到git服務器的git用戶家目錄authorized_keys文件里面。
- SVN 只有trunk,branches,沒有tags導出方法。
1 |
git svn clone svn://192.168.1.10:8888/svnproject/ --no-metadata --authors-file=userinfo.txt --trunk=trunk --branches=branches |
2 |
--ignore-refs=refs/remotes/yanziios1.* gitproject |
- git clone 遠程分支git clone git@192.168.1.222:/data/gitdata/yanzi/test.git–branch test-build-1442-branch-001 test-001
- 更多的錯誤詳見making git-svn work on mac tiger
git 恢復刪除文件
git 從使用的角度來說,的確沒有svn方便
svn直接update即可恢復,但git pull卻顯示already up-to-date
要查看刪除的文件: git ls-files --deleted
恢復則需要從新checkout: git checkout <deleted_file>
多個文件同時操作可以使用xargs
git ls-files -d | xargs git checkout master
Posted in git.
git 處理大文件加入版本庫
在使用git做為版本庫的時候,遇到一個問題,那就是超大文件無法上傳。git我不僅僅是拿來做代碼的備份,甚至一些文檔,我也拿它來處理,所以這些帶有圖片的文檔就讓我很郁悶了。它們可是都有着30M左右,甚至更大。怎么辦?
其實很簡單,在項目的.git/config里加入:
1 |
[pack] |
2 |
threads = 1 |
3 |
deltaCacheSize = 128m |
4 |
packSizeLimit = 128m |
5 |
windowMemory = 128m |
6 |
[core] |
7 |
packedGitLimit = 128m |
8 |
packedGitWindowSize = 128m |
Posted in git.
git 同時提交到多個版本庫
如果你維護了多個git在線平台的版本庫,你就會遇到,如何將一份代碼在push的時候推到所有的版本庫呢?
1 |
git remote add origin git@git.aikaiyuan.com:git/code.git |
- http://segmentfault.com/q/1010000000367632
- http://blog.codepiano.com/2013/07/03/push-multi-remote-repositories/
Posted in git.
Category Archives: git
GIT SVN DCOMMIT 提交失敗,原因:ASSERTION “SVN_FSPATH__IS_CANONICAL(CHILD_FSPATH)” FAILE
git svn dcommit 提交失敗,原因:assertion “svn_fspath__is_canonical(child_fspath)” failed
在使用 git svn 作為客戶端對一個 svn 庫進行提交的時候出現了錯誤:
git svn dcommit
Committing to https://xx.xx.xx.xx/svn/xyz/trunk …
R CODING_STYLE.md => doc/CODING_STYLE.md
assertion “svn_fspath__is_canonical(child_fspath)” failed: file “/usr/src/packages/subversion/subversion-1.8.5-1/src/subversion-1.8.5/subversion/libsvn_subr/dirent_uri.c”, line 2504, function: svn_fspath__skip_ancestor
error: git-svn died of signal 6
錯誤發生在 cygwin 下,git 版本 1.7.9,svn 版本 1.8.5。
stackoverflow 上說,原因是 git 的重命名檢測機制與 svn 發生了沖突。有兩個解決方案:
- 把 svn 降級到 1.7.9,一勞永逸。
- 使用
git svn dcommit -C1 -l1來提交。這樣會關閉 git 的重命名檢測機制,這次提交會丟失重命名操作,取而代之的是一次 remove 和 一次 add 操作,就和 svn 1.4 一樣。
在Linux上用Apache搭建Git服務器
最近在學Linux,終於在Linux上用Apache搭建起了Git服務器,在此記錄一下。
服務器:阿里雲服務器
Linux版本:CentOS 6.5
Apache版本:Apache/2.2.15
Git版本:git 1.7.1
Git訪問方式:基於http的基本驗證(非SSL)
Apache的安裝
1. 安裝Apache軟件:yum install httpd
2. 設置Apache在服務器啟動時運行:chkconfig –levels 235 httpd on
Git的安裝與配置
1. 安裝git
yum install git
2. 安裝 git-core(為了使用git-http-backend——支持git的CGI程序,apache支持git就靠它)
yum install git-core
3. 創建存放git repository的文件夾,比如這里是/home/git
cd /home && mkdir git && cd git
4. 創建一個空的項目
mkdir git-test && cd git-test
5. 修改上一步創建的文件夾git-test的所有者與所屬群組,要讓apache能讀/寫這個文件夾
chown -R apache:apache .
Apache的配置
1. 創建用於git用戶驗證的帳戶(用戶帳戶由apache管理)
1.1 創建新用戶
htpasswd -m -c /etc/httpd/conf.d/git-team.htpasswd <username>
然后輸入該用戶要使用的密碼。
1.2 修改git-team.htpasswd文件的所有者與所屬群組
chown apache:apache /etc/httpd/conf.d/git-team.htpasswd
1.3 設置git-team.htpasswd文件的訪問權限
chmod 640 /etc/httpd/conf.d/git-team.htpasswd
2. 修改apache配置文件httpd.conf
2.1 用vim打開httpd.conf:vi /etc/httpd/conf/httpd.conf
2.2 將光標移至文件結尾:0G
2.3 添加如下的內容:
<VirtualHost *:80>
ServerName git.cnblogs.com
SetEnv GIT_HTTP_EXPORT_ALL
SetEnv GIT_PROJECT_ROOT /home/git
ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/
<Location />
AuthType Basic
AuthName "Git"
AuthUserFile /etc/httpd/conf.d/git-team.htpasswd
Require valid-user
</Location>
</VirtualHost>
ServerName是git服務器的域名
/home/git是代碼庫存放的文件夾
ScriptAlias是將以/git/開頭的訪問路徑映射至git的CGI程序git-http-backend
AuthUserFile是驗證用戶帳戶的文件
2.4 保存並退出:x
3. 重啟apache使設置生效
service httpd restart
客戶端訪問Git服務器
運行以下命令簽出git-test項目:
git clone http://git.cnblogs.com/git/git-test
輸入用戶名與密碼,如果輸出下面的信息,就說明簽出成功。
remote: Counting objects: 6, done. remote: Compressing objects: 100% (4/4), done. remote: Total 6 (delta 0), reused 0 (delta 0) Unpacking objects: 100% (6/6), done.
在 CentOS 上部署 GitLab (自托管的Git項目倉庫)
參考資料
https://github.com/mattias-ohlsson/gitlab-installer/blob/master/gitlab-install-el6.sh
環境准備
OS: CentOS 6.3 x86_64
1.初識GitLab
GitLab是一個利用 Ruby on Rails 開發的開源應用程序,實現一個自托管的Git項目倉庫,可通過Web界面進行訪問公開的或者私人項目。
它擁有與Github類似的功能,能夠瀏覽源代碼,管理缺陷和注釋。可以管理團隊對倉庫的訪問,它非常易於瀏覽提交過的版本並提供一個文件歷史庫。團隊成員可以利用內置的簡單聊天程序(Wall)進行交流。它還提供一個代碼片段收集功能可以輕松實現代碼復用,便於日后有需要的時候進行查找。
GitLab 要求服務器端采用 Gitolite 搭建,5.0版本以后對於ssh服務,GitLab不再使用 Gitolite ,采用自己開發的 gitlab-shell 來實現。
在GitHub上托管代碼,私人項目是需要付費的,並且對於企業而言,還是將Git服務器放在內部要更加安全一些。因此,如果喜歡GitHub這種簡潔風格的Git服務器,在本地搭建一個GitLab是一個非常不錯的選擇。
另外,如果需要對代碼進行Review,推薦使用Gerrit,要復雜一些,但是功能非常強大。
2.安裝部署GitLab
2.1 如果有條件,提供一台全新的Server,僅僅只安裝了一些系統的軟件包,可以直接使用一鍵安裝的腳本來搭建,非常容易,具體步驟如下:
2.1.1 安裝EPEL擴展源
切換到root用戶
$ sudo -i
# rpm -ivh http://fr2.rpmfind.net/linux/epel/6/x86_64/epel-release-6-8.noarch.rpm
2.1.2 安裝git
# yum install git
2.1.3 下載gitlab-installer.sh安裝腳本
# git clone https://github.com/mattias-ohlsson/gitlab-installer.git
2.1.4 執行安裝腳本
# cd gitlab-installer/
# ./gitlab-install-el6.sh
等待腳本執行完畢后,會提示如下信息(比如Server主機名為:heydevops-node-2):
### Done ########################################
#
# You have your MySQL root password in this file:
# /config/database.yml
#
# Point your browser to:
# http://heydevops-node-2 (or: http://[host-ip])
# Default admin username: admin@local.host
# Default admin password: 5iveL!fe
#
#################################################
2.1.5 將腳本的Ruby版本指向到ruby-1.9.3-p392
# vim /home/git/gitlab-shell/bin/gitlab-shell
#!/usr/local/rvm/bin/ruby-1.9.3-p392
2.1.6 使用GitLab
接着,就可以通過 http://[host-ip] ([host-ip]是Server的IP)來訪問GitHub了。
首先,會看到如下所示的登陸界面:
通過上面提示信息內的賬號密碼登陸,登陸過后首先新增一個Project:
添加Project過后,會有一個配置向導,提供了非常詳細的本地Git配置步驟:
在進行這些本地配置之前,首先要在本地生成SSH-Keygen,並將Public Key添加到GitLab中:
# ssh-keygen -t rsa
# cat .ssh/id_rsa.pub
然后將所查看到的信息,都添加到GitLab的 MyProfile – SSH Key – Add New 中:
接着,就可以再本地按照圖片中所示的步驟進行操作並使用GitLab了。
2.2 上面的部署步驟,主要是采用了腳本gitlab-install-el6.sh來實現的,里面其實包含了很多的配置步驟,如果本地不是一個全新的環境,那么我們最好按照以下步驟來進行手動配置:
2.2.1 安裝EPEL擴展源
切換到root用戶
$ sudo -i
# rpm -ivh http://fr2.rpmfind.net/linux/epel/6/x86_64/epel-release-6-8.noarch.rpm
2.2.2 安裝git
# yum install git
2.2.3 安裝系統依賴
# yum -y install patch gcc-c++ readline-devel zlib-devel libffi-devel openssl-devel make autoconf automake libtool bison libxml2-devel libxslt-devel libyaml-devel
2.2.4 安裝rvm
# curl -L get.rvm.io | sudo bash -s stable
# source /etc/profile.d/rvm.sh
# rvm pkg install libyaml
# rvm –default use 1.9.3-p392
# gem install bundler
2.2.5 創建git用戶
# adduser –system –create-home –comment ‘GitLab’ git
2.2.6 配置gitlab-shell(比如Server主機名為:heydevops-node-2)
# su – git -c “git clone https://github.com/gitlabhq/gitlab-shell.git”
# su – git -c “cp gitlab-shell/config.yml.example gitlab-shell/config.yml”
# su – git -c “gitlab-shell/bin/install”
# chmod 600 /home/git/.ssh/authorized_keys
# chmod 700 /home/git/.ssh
2.2.7 安裝Redis
# yum -y install redis
# service redis start
# chkconfig redis on
2.2.8 安裝配置MySQL
# yum install -y mysql-server
# chkconfig mysqld on
# echo “CREATE DATABASE IF NOT EXISTS gitlabhq_production DEFAULT CHARACTER SET ‘utf8′ COLLATE ‘utf8_unicode_ci';” | mysql -u root
# echo “UPDATE mysql.user SET Password=PASSWORD(‘gitlab’) WHERE User=’root'; FLUSH PRIVILEGES;” | mysql -u root
2.2.9 安裝配置GitLab
# su – git -c “git clone https://github.com/gitlabhq/gitlabhq.git gitlab”
# su – git -c “cd gitlab;git checkout 5-0-stable”
# cd /home/git/gitlab
# su git -c “cp config/gitlab.yml.example config/gitlab.yml”
# sed -i “s/ host: localhost/ host: heydevops-node-2/g” config/gitlab.yml
# sed -i “s/from: gitlab@localhost/from: gitlab@heydevops-node-2/g” config/gitlab.yml
2.2.10 創建Unicorn配置文件
# su git -c “cp config/unicorn.rb.example config/unicorn.rb”
# sed -i “s/^listen/#listen/g” /home/git/gitlab/config/unicorn.rb
# sed -i “s/#listen “127.0.0.1:8080″/listen “127.0.0.1:3000″/g” /home/git/gitlab/config/unicorn.rb
# su git -c “cp config/database.yml.mysql config/database.yml”
# sed -i “s/secure password/gitlab/g” config/database.yml
# su git -c ‘git config –global user.name “GitLab”‘
# su git -c ‘git config –global user.email “gitlab@$GL_HOSTNAME”‘
2.2.10 安裝Gems
# yum -y install libicu-devel
# gem install charlock_holmes –version ‘0.6.9’
# yum -y install mysql-devel
# su git -c “bundle install –deployment –without development test postgres”
# export force=yes
# su git -c “bundle exec rake gitlab:setup RAILS_ENV=production”
# curl –output /etc/init.d/gitlab https://raw.github.com/gitlabhq/gitlab-recipes/master/init.d/gitlab-CentOS
# chmod +x /etc/init.d/gitlab
# sed -i “17 a source /etc/profile.d/rvm.shnrvm use 1.9.3-p392″ /etc/init.d/gitlab
# chkconfig gitlab on
# service gitlab start
2.2.11 安裝Apache
# yum -y install httpd
# chkconfig httpd on
# vim /etc/httpd/conf.d/gitlab.conf
ProxyPass / http://127.0.0.1:3000/
ProxyPassReverse / http://127.0.0.1:3000/
ProxyPreserveHost On
# setenforce 0
# service httpd start
2.2.12 停止iptables
# service iptables stop
2.2.13 修復gitlab-shell
# vim /home/git/gitlab-shell/bin/gitlab-shell
將腳本的Ruby版本指向到ruby-1.9.3-p392
#!/usr/local/rvm/bin/ruby-1.9.3-p392
2.2.14 完成,剩下的GitLab使用步驟與2.1.6相同。
GitLab 官方安裝文檔中文翻譯
譯者注:gitlabhq + gitolite是目前為止個人認為最好用的 git 中心庫管理系統,但是其安裝配置不是一般的復雜,找了半天沒發現完整的中文安裝文檔,只好依靠自己蹩腳的英文班門弄斧下,若有錯誤還請見諒。
原文地址:https://github.com/gitlabhq/gitlabhq/blob/stable/doc/installation.md
譯者:殷志剛
平台需求:
此項目被設計用於Linux操作系統。
也許可以工作在 FreeBSD 與 Mac OS 系統,但我們無法保證系統穩定性與功能完整性。
官方支持的 Linux 發行版:
- Ubuntu Linux
- Debian/GNU Linux
它應該工作於:
- Fedora
- CentOS
- RedHat
你使用這些系統需要些運氣,但不保證穩定性:
- MacOS X
- FreeBSD
GitLab 不能運行於 Windows 並且我們也沒有支持的計划。
硬件需求:
我們推薦至少 1GB 內容用於 gitlab 實例。
本安裝指南已於 Debian/Ubuntu 測試通過。
- 安裝總共需要6步:
- 安裝依賴包
- 安裝 Ruby
- 安裝 Gitolite
- 安裝與配置 GitLab
- 啟動前端Web服務器
- 啟動Resque進行(用於后台任務)
重要信息
在你發郵件列表詢問安裝與配置問題之前請確認你已經根據本文完成了所有步驟。
Only create a GitHub Issue if you want a specific part of this installation guide updated.
Also read the Read this before you submit an issue wiki page.
使用這個安裝腳本可以輕易的跳過前3個步驟。
# 安裝 curl 與 sudo apt-get install curl sudo # 三合一命令 :) curl https://raw.github.com/gitlabhq/gitlab-recipes/master/install/debian_ubuntu.sh | sh現在你可以直接到到第四步
如果你在 Amazon Web Services 使用 Ubuntu 12.04,你可以使用一個命令跳過所有步驟(1-6)
curl https://raw.github.com/gitlabhq/gitlab-recipes/master/install/debian_ubuntu_aws.sh | sh更多詳細信息,你可以閱讀此腳本的 HOWTO 部分。
1. 安裝依賴包
請記住,Debian 默認並沒有安裝 sudo,請使用 root 安裝它:
apt-get update && apt-get upgrade && apt-get install sudo
現在你可以安裝必須包:
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install -y wget curl gcc checkinstall libxml2-dev libxslt-dev libcurl4-openssl-dev libreadline6-dev libc6-dev libssl-dev libmysql++-dev make build-essential zlib1g-dev libicu-dev redis-server openssh-server git-core python-dev python-pip libyaml-dev postfix libpq-dev
數據庫
SQLite
sudo apt-get install -y sqlite3 libsqlite3-dev
MySQL
sudo apt-get install -y mysql-server mysql-client libmysqlclient-dev
# Login to MySQL
$ mysql -u root -p
# Create the GitLab production database
mysql> CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
# Create the MySQL User change $password to a real password
mysql> CREATE USER 'gitlab'@'localhost' IDENTIFIED BY '$password';
# Grant proper permissions to the MySQL User
mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'gitlab'@'localhost';
PostgreSQL
sudo apt-get install -y postgresql-9.2 postgresql-server-dev-9.2 # Connect to database server sudo -u postgres psql -d template1 # Add a user called gitlab. Change $password to a real password template1=# CREATE USER gitlab WITH PASSWORD '$password'; # Create the GitLab production database template1=# CREATE DATABASE IF NOT EXISTS gitlabhq_production; # Grant all privileges on database template1=# GRANT ALL PRIVILEGES ON DATABASE gitlabhq_production to gitlab; # Quit from PostgreSQL server template1=# q # Try connect to new database $ su - gitlab $ psql -d gitlabhq_production -U gitlab
(譯者注:以上3種數據庫根據需要安裝其一即可)
2. 安裝 Ruby
wget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p194.tar.gz tar xfvz ruby-1.9.3-p194.tar.gz cd ruby-1.9.3-p194 ./configure make sudo make install
3. 安裝 Gitolite
為 Git 創建用戶:
sudo adduser --system --shell /bin/sh --gecos 'git version control' --group --disabled-password --home /home/git git
為 GitLab 創建用戶:
# ubuntu/debian sudo adduser --disabled-login --gecos 'gitlab system' gitlab
將 gitlab 用戶添加到 git 用戶組:
sudo usermod -a -G git gitlab
將 git 用戶添加到 gitlab 用戶組:
sudo usermod -a -G gitlab git
生成密鑰:
sudo -H -u gitlab ssh-keygen -q -N '' -t rsa -f /home/gitlab/.ssh/id_rsa
克隆 GitLab 的 Gitolite 分支源代碼:
sudo -H -u git git clone -b gl-v304 https://github.com/gitlabhq/gitolite.git /home/git/gitolite
安裝:
cd /home/git sudo -u git -H mkdir bin sudo -u git sh -c 'echo -e "PATH=$PATH:/home/git/binnexport PATH" >> /home/git/.profile' sudo -u git sh -c 'gitolite/install -ln /home/git/bin' sudo cp /home/gitlab/.ssh/id_rsa.pub /home/git/gitlab.pub sudo chmod 0444 /home/git/gitlab.pub sudo -u git -H sh -c "PATH=/home/git/bin:$PATH; gitolite setup -pk /home/git/gitlab.pub"
權限:
sudo chmod -R g+rwX /home/git/repositories/ sudo chown -R git:git /home/git/repositories/
檢查:退出並重新登錄以使 git 用戶組生效
# 克隆 admin 資源庫以將 localhost 添加到 known_hosts # 並且確認 gitlab 用戶有權訪問 gitolite sudo -u gitlab -H git clone git@localhost:gitolite-admin.git /tmp/gitolite-admin # 如果執行成功,你可以將其刪除 sudo rm -rf /tmp/gitolite-admin
重要! 如果你不能克隆 gitolite-admin 資源庫,請不要繼續本次安裝,請根據 Trouble Shooting Guide 並且確認你已經小心的完成上文的全部步驟。
4. 克隆 GitLab 源代碼並安裝先決條件
sudo gem install charlock_holmes --version '0.6.8'
sudo pip install pygments
sudo gem install bundler
cd /home/gitlab
# Get gitlab code. Use this for stable setup
sudo -H -u gitlab git clone -b stable https://github.com/gitlabhq/gitlabhq.git gitlab
# Skip this for stable setup.
# Master branch (recent changes, less stable)
sudo -H -u gitlab git clone -b master https://github.com/gitlabhq/gitlabhq.git gitlab
cd gitlab
# Rename config files
sudo -u gitlab cp config/gitlab.yml.example config/gitlab.yml
(譯者注:本人在安裝 charlock_holmes 時遇到了點兒麻煩,解決辦法見這里)
選擇你希望使用的數據庫
# SQLite
sudo -u gitlab cp config/database.yml.sqlite config/database.yml
# Mysql
sudo -u gitlab cp config/database.yml.mysql config/database.yml
# PostgreSQL
sudo -u gitlab cp config/database.yml.postgres config/database.yml
# 修改 config/database.yml 確認輸入了正確的用戶名/密碼
安裝數據庫 gems
# mysql
sudo -u gitlab -H bundle install --without development test sqlite postgres --deployment # 或者 postgres sudo -u gitlab -H bundle install --without development test sqlite mysql --deployment # 或者 sqlite sudo -u gitlab -H bundle install --without development test mysql postgres --deployment
初始化數據庫
sudo -u gitlab bundle exec rake gitlab:app:setup RAILS_ENV=production
設置 GitLab hooks
sudo cp ./lib/hooks/post-receive /home/git/.gitolite/hooks/common/post-receive sudo chown git:git /home/git/.gitolite/hooks/common/post-receive
確認應用程序狀態:
sudo -u gitlab bundle exec rake gitlab:app:status RAILS_ENV=production # OUTPUT EXAMPLE Starting diagnostic config/database.yml............exists config/gitlab.yml............exists /home/git/repositories/............exists /home/git/repositories/ is writable?............YES remote: Counting objects: 603, done. remote: Compressing objects: 100% (466/466), done. remote: Total 603 (delta 174), reused 0 (delta 0) Receiving objects: 100% (603/603), 53.29 KiB, done. Resolving deltas: 100% (174/174), done. Can clone gitolite-admin?............YES UMASK for .gitolite.rc is 0007? ............YES /home/git/share/gitolite/hooks/common/post-receive exists? ............YES
如果所有結果都是 YES,恭喜!你可以繼續進行下一步了。
5. 設置 web server
應用可以用下一個命令行動:
# 用於測試目的 sudo -u gitlab bundle exec rails s -e production # 用於守護進程 sudo -u gitlab bundle exec rails s -e production -d
默認登錄用戶名及密碼:
admin@local.host 5iveL!fe
6. 運行 Resque 進程(用於處理工作隊列)
# 手動啟動 sudo -u gitlab bundle exec rake environment resque:work QUEUE=* RAILS_ENV=production BACKGROUND=yes # GitLab 啟動腳本 sudo -u gitlab ./resque.sh # 如果你使用 root 運行此腳本,會導致 /home/gitlab/gitlab/tmp/pids/resque_worker.pid 文件的擁有者為 root # 將導致 resque 在下一次系統初始化中無法啟動
自定義 Resque 使用的 Redis 連接
如果你希望 Resque 連接到一個非標准端口號或另一台服務器上的 Redis,你可以在 config/resque.yml 文件修改連接信息:
production: redis.example.com:6379
好了,我們已經擁有了一個工作正常的 GitLab 了,但請繼續下去,有一些事情是必須完成的。
Nginx 與 Unicorn
1. Unicorn
cd /home/gitlab/gitlab sudo -u gitlab cp config/unicorn.rb.example config/unicorn.rb sudo -u gitlab bundle exec unicorn_rails -c config/unicorn.rb -E production -D
2. Nginx
# 初次安裝 Nginx
sudo apt-get install nginx
# 添加GitLab 到 nginx sites
sudo wget https://raw.github.com/gitlabhq/gitlab-recipes/master/nginx/gitlab -P /etc/nginx/sites-available/
sudo ln -s /etc/nginx/sites-available/gitlab /etc/nginx/sites-enabled/gitlab
# 修改 **YOUR_SERVER_IP** 與 **YOUR_SERVER_FQDN**
# 為起初的 IP 地址與准備讓 GitLab 服務的域名
sudo vim /etc/nginx/sites-enabled/gitlab
# 重啟 nginx:
sudo /etc/init.d/nginx restart
3. Init 腳本
在 /etc/init.d/gitlab 創建 init 腳本:
sudo wget https://raw.github.com/gitlabhq/gitlab-recipes/master/init.d/gitlab -P /etc/init.d/ sudo chmod +x /etc/init.d/gitlab
設置 GitLab 自動啟動:
sudo update-rc.d gitlab defaults 21
現在你可以用這種方式啟動/重啟/停止 GitLab 服務:
sudo /etc/init.d/gitlab restart
譯者后注:其實通篇主要的全是各種命令,其實不看說明一條命令一條命令的復制粘貼也能安裝完成,當然前提是你使用的是Ubuntu/Debian,回頭有時間再寫些其他系統的實際安裝過程。
Posted in git.
CentOS 上GitLab的搭建
事情的起因是因為導師提到讓我在實驗室服務器搭建一個Git服務器供大家使用,於是我就在網上搜索解決方案,最后選定了兩個gitblit以及gitlab,不過最后發現服務器是windows server 2008 r2,gitlab沒法部署,最后退而求其次部署了gitblit,感覺速度還蠻不錯,功能也可以,就是一點,界面不如gitlab好看。
后來就心癢難耐,覺得gitlab很漂亮,結果就想着在自己vps部署一個,於是就開始了噩夢一般的部署過程。開正體前,我再感嘆下,實在是太麻煩了,尤其是在centos 5這種老系統上面。
1.添加EPEL源
不添加這個,什么依賴都裝不了。所以,你懂得。這個是centos 5的,其他版本的可以去網上搜,就地址不一樣。
| 1 | rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-5-4.noarch.rpm |
2.安裝依賴
就是安裝依賴,建議python自己編譯安裝一個,版本新一點。
|
1
2
|
yum -y groupinstall
'Development Tools'
'Additional Development'
yum -y
install
readline readline-devel ncurses-devel gdbm-devel glibc-devel tcl-devel openssl-devel curl-devel expat-devel db4-devel byacc sqlite-devel gcc-c++ libyaml libyaml-devel libffi libffi-devel libxml2 libxml2-devel libxslt libxslt-devel libicu libicu-devel system-config-firewall-tui python-devel redis
|
3.安裝Ruby
安裝Ruby,千萬不要用最新版,要用p327版本
|
1
2
3
4
|
wget http:
//ftp
.ruby-lang.org
/pub/ruby/1
.9
/ruby-1
.9.3-p327.
tar
.gz
tar
xfvz ruby-1.9.3-p327.
tar
.gz
cd
ruby-1.9.3-p327
.
/configure
--disable-
install
-doc --
enable
-shared --disable-pthread
|
編譯前,如果可以的話,最好安裝下qt
|
1
2
|
yum
install
qt-devel qtwebkit-devel
export
PATH=$PATH:
/usr/lib32/qt4/bin
# 32位和64位,你懂得
|
編譯安裝
| 1 | make && make install |
4.更新gem,安裝rails
|
1
2
3
|
gem update --system
gem update
gem
install
rails
|
5.Gitolite安裝
添加兩個用戶,安裝證書
|
1
2
3
4
|
adduser --shell
/bin/bash
--create-home --home-
dir
/home/gitlab
gitlab
adduser --system --shell
/bin/sh
--comment
'gitolite'
--create-home --home-
dir
/home/git
git
sudo
-u gitlab -H
ssh
-keygen -q -N
''
-t rsa -f
/home/gitlab/
.
ssh
/id_rsa
sudo
usermod
-a -G git gitlab
|
Gitolite安裝
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
cd
/home/git
sudo
-u git -H git clone -b gl-v320 https:
//github
.com
/gitlabhq/gitolite
.git
/home/git/gitolite
# Add Gitolite scripts to $PATH
sudo
-u git -H
mkdir
/home/git/bin
sudo
-u git -H sh -c
'printf "%bn%bn" "PATH=$PATH:/home/git/bin" "export PATH" >> /home/git/.profile'
sudo
-u git -H sh -c
'gitolite/install -ln /home/git/bin'
# Copy the gitlab user's (public) SSH key ...
sudo
cp
/home/gitlab/
.
ssh
/id_rsa
.pub
/home/git/gitlab
.pub
sudo
chmod
0444
/home/git/gitlab
.pub
# ... and use it as the admin key for the Gitolite setup
sudo
-u git -H sh -c
"PATH=/home/git/bin:$PATH; gitolite setup -pk /home/git/gitlab.pub"
# Make sure the Gitolite config dir is owned by git
sudo
chmod
-R 750
/home/git/
.gitolite/
sudo
chown
-R git:git
/home/git/
.gitolite/
# Make sure the repositories dir is owned by git and it stays that way
sudo
chmod
-R ug+rwXs,o-rwx
/home/git/repositories/
sudo
chown
-R git:git
/home/git/repositories/
|
設置ssh安全選項(這個可能沒用)
|
1
2
3
4
5
6
7
8
9
10
11
12
|
echo
"Host localhost
StrictHostKeyChecking no
UserKnownHostsFile=
/dev/null
" |
sudo
tee
-a
/etc/ssh/ssh_config
echo
"Host YOUR_DOMAIN_NAME
StrictHostKeyChecking no
UserKnownHostsFile=
/dev/null
" |
sudo
tee
-a
/etc/ssh/ssh_config
# If gitolite domain differs
echo
"Host YOUR_GITOLITE_DOMAIN
StrictHostKeyChecking no
UserKnownHostsFile=
/dev/null
" |
sudo
tee
-a
/etc/ssh/ssh_config
|
測試gitolite安裝
|
1
2
3
4
5
6
|
# Clone the admin repo so SSH adds localhost to known_hosts ...
# ... and to be sure your users have access to Gitolite
sudo
-u gitlab -H git clone git@localhost:gitolite-admin.git
/tmp/gitolite-admin
# If it succeeded without errors you can remove the cloned repo
sudo
rm
-rf
/tmp/gitolite-admin
|
6. 安裝Gitlab
首先下載下來
|
1
2
3
4
5
6
7
8
9
10
|
# We'll install GitLab into home directory of the user "gitlab"
cd
/home/gitlab
# Clone GitLab repository
sudo
-u gitlab -H git clone https:
//github
.com
/gitlabhq/gitlabhq
.git gitlab
# Go to gitlab dir
cd
/home/gitlab/gitlab
# Checkout to stable release
sudo
-u gitlab -H git checkout 4-0-stable
|
設置權限還有其他選項
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
cd
/home/gitlab/gitlab
# Copy the example GitLab config
sudo
-u gitlab -H
cp
config
/gitlab
.yml.example config
/gitlab
.yml
# 把其中的gitlab部分和ssh部分的host改成自己的域名就行了
sudo
-u gitlab -H vim config
/gitlab
.yml
# Make sure GitLab can write to the log/ and tmp/ directories
sudo
chown
-R gitlab log/
sudo
chown
-R gitlab tmp/
sudo
chmod
-R u+rwX log/
sudo
chmod
-R u+rwX tmp/
# Copy the example Unicorn config
sudo
-u gitlab -H
cp
config
/unicorn
.rb.example config
/unicorn
.rb
|
數據庫設置
|
1
2
3
4
5
|
# Mysql
sudo
-u gitlab
cp
config
/database
.yml.mysql config
/database
.yml
# PostgreSQL
|
安裝Gems
|
1
2
3
4
5
6
7
8
9
|
cd
/home/gitlab/gitlab
sudo
gem
install
charlock_holmes --version
'0.6.9'
# For mysql db
sudo
-u gitlab -H bundle
install
--deployment --without development
test
postgres
# Or For postgres db
|
額外設置
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
# 設置git全局設置
sudo
-u gitlab -H git config --global user.name
"GitLab"
sudo
-u gitlab -H git config --global user.email
"gitlab@localhost"
# 設置Hook腳本
sudo
cp
.
/lib/hooks/post-receive
/home/git/
.gitolite
/hooks/common/post-receive
sudo
chown
git:git
/home/git/
.gitolite
/hooks/common/post-receive
# 初始化數據庫
sudo
-u gitlab -H bundle
exec
rake gitlab:app:setup RAILS_ENV=production
# 安裝初始化腳本,這是centos,ubuntu有對應的腳本
sudo
wget https:
//raw
.github.com
/gitlabhq/gitlab-recipes/master/init
.d
/gitlab-centos
-P
/etc/init
.d/
sudo
chmod
+x
/etc/init
.d
/gitlab-centos
chkconfig --add gitlab-centos
|
測試gitlab的狀態,正常則啟動
|
1
2
3
4
5
6
7
8
|
# 查看環境信息
sudo
-u gitlab -H bundle
exec
rake gitlab:
env
:info RAILS_ENV=production
# 檢測gitlab狀態,非綠色的太多了,要注意修復下
sudo
-u gitlab -H bundle
exec
rake gitlab:check RAILS_ENV=production
# 啟動
sudo
service gitlab start
|
7. Nginx配置
安裝就不說了,配置寫法,這個是http
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# GITLAB
# Maintainer: @randx
# App Version: 4.0
upstream gitlab {
server unix:/home/gitlab/gitlab/tmp/sockets/gitlab.socket;
}
server {
listen 80; # e.g., listen 192.168.1.1:80;
server_name Domain_NAME; # e.g., server_name source.example.com;
root /home/gitlab/gitlab/public;
# individual nginx logs for this gitlab vhost
access_log /var/log/nginx/gitlab_access.log;
error_log /var/log/nginx/gitlab_error.log;
location / {
# serve static files from defined root folder;.
# @gitlab is a named location for the upstream fallback, see below
try_files $uri $uri/index.html $uri.html @gitlab;
}
# if a file, which is not found in the root folder is requested,
# then the proxy pass the request to the upsteam (gitlab unicorn)
location @gitlab {
proxy_read_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694
proxy_connect_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694
proxy_redirect off;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://gitlab;
}
}
|
https的對應配置,建議使用最新版openssl編譯nginx可以激活ECDHE前向加密。加密算法建議使用AES 不過首先應該先自己簽名一個證書
|
1
2
|
sudo
openssl req -new -x509 -nodes -days 3560 -out gitlab.crt -keyout gitlab.key
sudo
chmod
o-r gitlab.key
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# GITLAB
# Maintainer: @randx
# App Version: 4.0
upstream gitlab {
server unix:/home/gitlab/gitlab/tmp/sockets/gitlab.socket;
}
# This is a normal HTTP host which redirects all traffic to the HTTPS host.
server {
listen 80;
listen [::]:80;
server_name Domain_NAME;
root /nowhere;
rewrite ^ https://gitlab.stardrad.com$request_uri permanent;
}
server {
listen 443;
listen [::]:443 ipv6only=on;
server_name Domain_NAME;
root /home/gitlab/gitlab/public;
ssl on;
ssl_certificate gitlab.crt;
ssl_certificate_key gitlab.key;
ssl_protocols SSLv3 TLSv1 TLSv2;
ssl_ciphers AES:HIGH:!ADH:!MD5;
ssl_prefer_server_ciphers on;
# individual nginx logs for this gitlab vhost
access_log /var/log/nginx/gitlab_access.log;
error_log /var/log/nginx/gitlab_error.log;
location / {
# serve static files from defined root folder;.
# @gitlab is a named location for the upstream fallback, see below
try_files $uri $uri/index.html $uri.html @gitlab;
}
# if a file, which is not found in the root folder is requested,
# then the proxy pass the request to the upsteam (gitlab unicorn)
location @gitlab {
proxy_read_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694
proxy_connect_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694
proxy_redirect off;
#proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-Ssl on;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://gitlab;
}
}
|
8. 完成
記住初始賬號密碼,登入即可
|
1
2
|
admin@local.host
5iveL!fe
|
附注
如果你的ssh的端口非標准的22(vps一般都是這樣),則應當修改配置文件
|
1
2
3
4
5
6
7
|
su
gitlab
vim ~/.
ssh
/config
# 在vim中插入
host localhost
user git
port 888
hostname
Your Ip or Your domain name
|
參考
centos安裝gitlab
最近換了公司,在交接公司,所以很忙也沒有時間寫博客,同時隨着能力的逐漸提升,很多知識感覺很簡單,也沒有必要專門寫博客,只是把遇到的情況與解決方法寫入到了筆記里,正好現在沒什么事,就把我最近研究的gitlab如何在centos里安裝的筆記分享給大家。
先給大家介紹一下gitlab
官方推薦的是那2個系統,但我這里需要安裝在centos里,所以沒辦法自己多研究與測試,總結的安裝經驗如下:
前置要求
一定要先關閉iptable與selinux
本文安裝的系統為centos 6.2 64位系統,安裝在dell r410機器
1、安裝epel與基礎依賴庫及軟件
1 |
cd /tmp |
3 |
rpm -Uvh epel-release-6-8.noarch.rpm |
4 |
yum install -y readline-devel libyaml-devel gdbm-devel ncurses-devel redis openssl-devel zlib-devel gcc gcc-c++ make autoconf readline-devel curl-devel expat-devel gettext-devel tk-devel libxml2-devel libffi-devel libxslt-devel libicu-devel httpd httpd-devel gitolite git-all python-devel python-pip <span id="54_nwp" style="width: auto; height: auto; float: none;"><a id="54_nwl" href="http://cpro.baidu.com/cpro/ui/uijs.php?rs=1&u=http%3A%2F%2Fwww%2Eaikaiyuan%2Ecom%2Fcategory%2Fgit%2Fpage%2F2&p=baidu&c=news&n=10&t=tpclicked3_hc&q=selboo1_cpr&k=sql&k0=sql&k1=%D6%D0%CE%C4&k2=access&k3=%C9%E7%C7%F8&k4=mysql&k5=server&sid=4d4e903e508bae91&ch=0&tu=u1896194&jk=115681819ccec6d1&cf=29&fv=14&stid=9&urlid=0&luki=7&seller_id=1&di=128" target="_blank" mpid="54" style="text-decoration: none;"><span style="color:#0000ff;font-size:13px;width:auto;height:auto;float:none;">sql</span></a></span>ite-devel sendmail vim <span id="55_nwp" style="width: auto; height: auto; float: none;"><a id="55_nwl" href="http://cpro.baidu.com/cpro/ui/uijs.php?rs=1&u=http%3A%2F%2Fwww%2Eaikaiyuan%2Ecom%2Fcategory%2Fgit%2Fpage%2F2&p=baidu&c=news&n=10&t=tpclicked3_hc&q=selboo1_cpr&k=mysql&k0=mysql&k1=server&k2=%CA%FD%BE%DD%BF%E2&k3=postgresql&k4=%BF%AA%D4%B4&k5=master&sid=4d4e903e508bae91&ch=0&tu=u1896194&jk=115681819ccec6d1&cf=29&fv=14&stid=9&urlid=0&luki=1&seller_id=1&di=128" target="_blank" mpid="55" style="text-decoration: none;"><span style="color:#0000ff;font-size:13px;width:auto;height:auto;float:none;">mysql</span></a></span>-devel mysql-<span id="56_nwp" style="width: auto; height: auto; float: none;"><a id="56_nwl" href="http://cpro.baidu.com/cpro/ui/uijs.php?rs=1&u=http%3A%2F%2Fwww%2Eaikaiyuan%2Ecom%2Fcategory%2Fgit%2Fpage%2F2&p=baidu&c=news&n=10&t=tpclicked3_hc&q=selboo1_cpr&k=server&k0=server&k1=%CA%FD%BE%DD%BF%E2&k2=postgresql&k3=%BF%AA%D4%B4&k4=master&k5=sql&sid=4d4e903e508bae91&ch=0&tu=u1896194&jk=115681819ccec6d1&cf=29&fv=14&stid=9&urlid=0&luki=2&seller_id=1&di=128" target="_blank" mpid="56" style="text-decoration: none;"><span style="color:#0000ff;font-size:13px;width:auto;height:auto;float:none;">server</span></a></span> patch libyaml* pcre-devel |
01 |
mkdir /tmp/ruby && cd /tmp/ruby |
02 |
curl --progress http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p392.tar.gz | tar xz |
03 |
cd ruby-1.9.3-p392/ |
04 |
./configure |
05 |
make |
06 |
make install |
07 |
gem install bundler |
08 |
ln -s /usr/local/bin/ruby /usr/bin/ruby |
09 |
ln -s /usr/local/bin/gem /usr/bin/gem |
10 |
ln -s /usr/local/bin/bundle /usr/bin/bundle |
git用戶供GitLab使用
1 |
adduser --comment 'GitLab' git |
2 |
chmod –R 755 /home/git |
01 |
# Login as git |
02 |
sudo su git |
03 |
# Go to home directory |
04 |
cd /home/git |
05 |
# Clone gitlab shell |
06 |
git clone https://github.com/gitlabhq/gitlab-shell.git |
07 |
cd gitlab-shell |
08 |
# switch to right version |
09 |
git checkout v1.3.0 |
10 |
cp config.yml.example config.yml |
11 |
# Edit config and replace gitlab_url |
12 |
# with something like 'http://domain.com/' |
13 |
vim config.yml |
14 |
# Do setup |
15 |
./bin/install |
01 |
# Login to MySQL |
02 |
<span id="52_nwp" style="width: auto; height: auto; float: none;"><a id="52_nwl" href="http://cpro.baidu.com/cpro/ui/uijs.php?rs=1&u=http%3A%2F%2Fwww%2Eaikaiyuan%2Ecom%2Fcategory%2Fgit%2Fpage%2F2&p=baidu&c=news&n=10&t=tpclicked3_hc&q=selboo1_cpr&k=mysql&k0=mysql&k1=server&k2=%CA%FD%BE%DD%BF%E2&k3=postgresql&k4=%BF%AA%D4%B4&k5=master&sid=4d4e903e508bae91&ch=0&tu=u1896194&jk=115681819ccec6d1&cf=29&fv=14&stid=9&urlid=0&luki=1&seller_id=1&di=128" target="_blank" mpid="52" style="text-decoration: none;"><span style="color:#0000ff;font-size:13px;width:auto;height:auto;float:none;">mysql</span></a></span> -u root -p |
03 |
# Create a user for GitLab. (change $password to a real password) |
04 |
mysql> CREATE USER 'gitlab'@'localhost' IDENTIFIED BY 'gitlab'; |
05 |
# Create the GitLab production database |
06 |
mysql> CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`; |
07 |
# Grant the GitLab user necessary permissopns on the table. |
08 |
mysql> GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'gitlab'@'localhost'; |
09 |
# Quit the database session |
10 |
<span id="53_nwp" style="width: auto; height: auto; float: none;"><a id="53_nwl" href="http://cpro.baidu.com/cpro/ui/uijs.php?rs=1&u=http%3A%2F%2Fwww%2Eaikaiyuan%2Ecom%2Fcategory%2Fgit%2Fpage%2F2&p=baidu&c=news&n=10&t=tpclicked3_hc&q=selboo1_cpr&k=mysql&k0=mysql&k1=server&k2=%CA%FD%BE%DD%BF%E2&k3=postgresql&k4=%BF%AA%D4%B4&k5=master&sid=4d4e903e508bae91&ch=0&tu=u1896194&jk=115681819ccec6d1&cf=29&fv=14&stid=9&urlid=0&luki=1&seller_id=1&di=128" target="_blank" mpid="53" style="text-decoration: none;"><span style="color:#0000ff;font-size:13px;width:auto;height:auto;float:none;">mysql</span></a></span>> q |
01 |
# Clone GitLab repository |
02 |
cd /home/git |
03 |
sudo -u git -H git clone https://github.com/gitlabhq/gitlabhq.git gitlab |
04 |
# Go to gitlab dir |
05 |
cd /home/git/gitlab |
06 |
# Checkout to stable release |
07 |
sudo -u git -H git checkout 5-1-stable |
08 |
Configure it |
09 |
cd /home/git/gitlab |
10 |
# Copy the example GitLab config |
11 |
sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml |
12 |
# Make sure to change "localhost" to the fully-qualified domain name of your |
13 |
# host serving GitLab where necessary |
14 |
sudo -u git -H vim config/gitlab.yml |
15 |
# Make sure GitLab can write to the log/ and tmp/ directories |
16 |
sudo chown -R git log/ |
17 |
sudo chown -R git tmp/ |
18 |
sudo chmod -R u+rwX log/ |
19 |
sudo chmod -R u+rwX tmp/ |
20 |
# Create directory for satellites |
21 |
sudo -u git -H mkdir /home/git/gitlab-satellites |
22 |
# Create directories for sockets/pids and make sure GitLab can write to them |
23 |
sudo -u git -H mkdir tmp/pids/ |
24 |
sudo -u git -H mkdir tmp/sockets/ |
25 |
sudo chmod -R u+rwX tmp/pids/ |
26 |
sudo chmod -R u+rwX tmp/sockets/ |
27 |
# Create public/uploads directory otherwise backup will fail |
28 |
sudo -u git -H mkdir public/uploads |
29 |
sudo chmod -R u+rwX public/uploads |
30 |
# Copy the example Puma config |
31 |
sudo -u git -H cp config/puma.rb.example config/puma.rb |
32 |
# Configure Git global settings for git user, useful when editing via web |
33 |
# Edit user.email according to what is set in gitlab.yml |
34 |
sudo -u git -H git config --global user.name "GitLab" |
35 |
sudo -u git -H git config --global user.email "gitlab@localhost" |
1 |
sudo -u git cp config/database.yml.<span id="51_nwp" style="width: auto; height: auto; float: none;"><a id="51_nwl" href="http://cpro.baidu.com/cpro/ui/uijs.php?rs=1&u=http%3A%2F%2Fwww%2Eaikaiyuan%2Ecom%2Fcategory%2Fgit%2Fpage%2F2&p=baidu&c=news&n=10&t=tpclicked3_hc&q=selboo1_cpr&k=mysql&k0=mysql&k1=server&k2=%CA%FD%BE%DD%BF%E2&k3=postgresql&k4=%BF%AA%D4%B4&k5=master&sid=4d4e903e508bae91&ch=0&tu=u1896194&jk=115681819ccec6d1&cf=29&fv=14&stid=9&urlid=0&luki=1&seller_id=1&di=128" target="_blank" mpid="51" style="text-decoration: none;"><span style="color:#0000ff;font-size:13px;width:auto;height:auto;float:none;">mysql</span></a></span> config/database.yml |
2 |
sudo -u git vim config/database.yml |
3 |
Make sure to update username/password in config/database.yml. |
這個數據庫的賬戶與密碼是在第5步那里創建的。
8、安裝gem
1 |
cd /home/git/gitlab |
2 |
sudo gem install charlock_holmes --version '0.6.9.4' |
3 |
sudo -u git -H bundle install --deployment --without development test postgres |
9、啟動redis
1 |
/etc/init.d/redis start |
10、對數據庫進行初始化
1 |
sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production |
11、下載啟動腳本
1 |
Download the init script (will be /etc/init.d/gitlab): |
2 |
sudo curl --output /etc/init.d/gitlab https://raw.github.com/gitlabhq/gitlabhq/<span id="49_nwp" style="width: auto; height: auto; float: none;"><a id="49_nwl" href="http://cpro.baidu.com/cpro/ui/uijs.php?rs=1&u=http%3A%2F%2Fwww%2Eaikaiyuan%2Ecom%2Fcategory%2Fgit%2Fpage%2F2&p=baidu&c=news&n=10&t=tpclicked3_hc&q=selboo1_cpr&k=master&k0=master&k1=sql&k2=%D6%D0%CE%C4&k3=access&k4=%C9%E7%C7%F8&k5=mysql&sid=4d4e903e508bae91&ch=0&tu=u1896194&jk=115681819ccec6d1&cf=29&fv=14&stid=9&urlid=0&luki=6&seller_id=1&di=128" target="_blank" mpid="49" style="text-decoration: none;"><span style="color:#0000ff;font-size:13px;width:auto;height:auto;float:none;">master</span></a></span>/lib/support/init.d/gitlab |
3 |
sudo chmod +x /etc/init.d/gitlab |
4 |
Make GitLab start on boot: |
5 |
chkconfig --add gitlab |
12、檢測應用狀態
01 |
Check if GitLab and its environment are configured correctly: |
02 |
sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production |
03 |
To make sure you didn't miss anything run a more thorough check with: |
04 |
sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production |
05 |
If all items are green, then congratulations on successfully installing GitLab! However there are still a few steps left. |
06 |
出現了Running? ... no |
07 |
Try fixing it: |
08 |
sudo -u git -H bundle exec rake sidekiq:start RAILS_ENV=production |
09 |
For more information see: |
10 |
doc/install/installation.md in section "Install Init Script" |
11 |
see log/sidekiq.log for possible errors |
12 |
Please fix the error above and rerun the checks. |
13 |
運行sudo -u git -H bundle exec rake sidekiq:start RAILS_ENV=production |
14 |
然后在運行sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production |
13、啟動gitlab
1 |
sudo service gitlab start |
14、下載nginx(我選nging作為web服務器)
1 |
yum install nginx |
15、下載官方提供gitlab的虛擬配置文件,並修改配置
01 |
Download an example site config: |
02 |
sudo curl --output /etc/nginx/conf.d/gitlab https://raw.github.com/gitlabhq/gitlabhq/<span id="47_nwp" style="width: auto; height: auto; float: none;"><a id="47_nwl" href="http://cpro.baidu.com/cpro/ui/uijs.php?rs=1&u=http%3A%2F%2Fwww%2Eaikaiyuan%2Ecom%2Fcategory%2Fgit%2Fpage%2F2&p=baidu&c=news&n=10&t=tpclicked3_hc&q=selboo1_cpr&k=master&k0=master&k1=sql&k2=%D6%D0%CE%C4&k3=access&k4=%C9%E7%C7%F8&k5=mysql&sid=4d4e903e508bae91&ch=0&tu=u1896194&jk=115681819ccec6d1&cf=29&fv=14&stid=9&urlid=0&luki=6&seller_id=1&di=128" target="_blank" mpid="47" style="text-decoration: none;"><span style="color:#0000ff;font-size:13px;width:auto;height:auto;float:none;">master</span></a></span>/lib/support/nginx/gitlab |
03 |
Make sure to edit the config file to match your setup: |
04 |
# **YOUR_SERVER_FQDN** to the fully-qualified |
05 |
# domain name of your host serving GitLab. Also, replace |
06 |
# the 'listen' line with the following: |
07 |
# listen 80 default_<span id="48_nwp" style="width: auto; height: auto; float: none;"><a id="48_nwl" href="http://cpro.baidu.com/cpro/ui/uijs.php?rs=1&u=http%3A%2F%2Fwww%2Eaikaiyuan%2Ecom%2Fcategory%2Fgit%2Fpage%2F2&p=baidu&c=news&n=10&t=tpclicked3_hc&q=selboo1_cpr&k=server&k0=server&k1=%CA%FD%BE%DD%BF%E2&k2=postgresql&k3=%BF%AA%D4%B4&k4=master&k5=sql&sid=4d4e903e508bae91&ch=0&tu=u1896194&jk=115681819ccec6d1&cf=29&fv=14&stid=9&urlid=0&luki=2&seller_id=1&di=128" target="_blank" mpid="48" style="text-decoration: none;"><span style="color:#0000ff;font-size:13px;width:auto;height:auto;float:none;">server</span></a></span>; # e.g., listen 192.168.1.1:80; |
08 |
sudo vim /etc/nginx/conf.d/gitlab |
09 |
cd /etc/nginx/conf.d |
10 |
mv default.conf default.conf.bak |
11 |
mv gitlab default.conf |
12 |
Restart |
13 |
sudo service nginx restart |
16、登陸你在nginx里添加的ip,然后輸入賬戶與密碼,默認為
1 |
admin@local.host |
2 |
5iveL!fe |
Posted in git.
Linux 下搭建 GitLab 服務器
這兩天因為項目需求需要搭建一個GitLab服務器,遇到了很多問題,參考了很多網絡資料,終於搭建成功,在此把這個過程記錄一下,利人利己。
一、最終目的
1,在Linux下創建GitLab服務器,客戶端能夠完成git 的 clone,pull,commit,push操作。
2,能夠通過瀏覽器訪問服務器上的GitLab主頁,登錄之后能夠實現,創建工程,增加用戶等操作。
二、准備知識
雖然按照后續過程能夠實現最終目的,但本人強烈建議讀者大致了解下以下知識點。(本人就是因為事先對有些知識不了解導致搭建過程中困難重重)
1,git的基本用法
2,gitolite和github
3,ssh認證
4,uginx代理服務器
三、搭建環境
服務器: Ubuntu11.04(本人使用的是虛擬機),需要已經啟動了ssh服務。
測試客戶端:Win7,需要先安裝git
四、開始搭建
原文鏈接地址
https://github.com/gitlabhq/gitlabhq/blob/stable/doc/installation.md
參考: http://www.zhigang.net/ (感謝這位網友的分享)
平台需求:
此項目被設計用於Linux操作系統。
也許可以工作在 FreeBSD 與 Mac OS 系統,但我們無法保證系統穩定性與功能完整性。
官方支持的 Linux 發行版:
- Ubuntu Linux
- Debian/GNU Linux
它應該工作於:
- Fedora
- CentOS
- RedHat
你使用這些系統需要些運氣,但不保證穩定性:
- MacOS X
- FreeBSD
GitLab 不能運行於 Windows 並且我們也沒有支持的計划。
硬件需求:
我們推薦至少 1GB 內容用於 gitlab 實例。
本安裝指南已於 Debian/Ubuntu 測試通過。
- 安裝總共需要6步:
- 安裝依賴包
- 安裝 Ruby
- 安裝 Gitolite
- 安裝與配置 GitLab
- 啟動前端Web服務器
- 啟動Resque進行(用於后台任務)
重要信息
在你發郵件列表詢問安裝與配置問題之前請確認你已經根據本文完成了所有步驟。
Only create a GitHub Issue if you want a specific part of this installation guide updated.
Also read the Read this before you submit an issue wiki page.
使用這個安裝腳本可以輕易的跳過前3個步驟。
# 安裝 curl 與 sudo apt-get install curl sudo # 三合一命令 :) curl https://raw.github.com/gitlabhq/gitlab-recipes/master/install/debian_ubuntu.sh | sh 使用這個命令默認的數據庫依賴包是mysql的.現在你可以直接到到第四步
如果你在 Amazon Web Services 使用 Ubuntu 12.04,你可以使用一個命令跳過所有步驟(1-6)
curl https://raw.github.com/gitlabhq/gitlab-recipes/master/install/debian_ubuntu_aws.sh | sh更多詳細信息,你可以閱讀此腳本的 HOWTO 部分。
筆者注:本人使用了三合一命令欲跳過前三步,但后續安裝怎么都不成功,后來才發現第二步安裝有問題,按照第2步要求安裝ruby就可以了。
所以請關注這個三個一命令狀態,確保都能執行成功。
1. 安裝依賴包
請記住,Debian 默認並沒有安裝 sudo,請使用 root 安裝它:
apt-get update && apt-get upgrade && apt-get install sudo
現在你可以安裝必須包:
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install -y wget curl gcc checkinstall libxml2-dev libxslt-dev libcurl4-openssl-dev libreadline6-dev libc6-dev libssl-dev libmysql++-dev make build-essential zlib1g-dev libicu-dev redis-server openssh-server git-core python-dev python-pip libyaml-dev postfix libpq-dev
數據庫
SQLite
sudo apt-get install -y sqlite3 libsqlite3-dev
MySQL
sudo apt-get install -y mysql-server mysql-client libmysqlclient-dev
# Login to MySQL
$ mysql -u root -p
# Create the GitLab production database
mysql> CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
# Create the MySQL User change $password to a real password
mysql> CREATE USER 'gitlab'@'localhost' IDENTIFIED BY '$password';
# Grant proper permissions to the MySQL User
mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'gitlab'@'localhost';
PostgreSQL
sudo apt-get install -y postgresql-9.2 postgresql-server-dev-9.2 # Connect to database server sudo -u postgres psql -d template1 # Add a user called gitlab. Change $password to a real password template1=# CREATE USER gitlab WITH PASSWORD '$password'; # Create the GitLab production database template1=# CREATE DATABASE IF NOT EXISTS gitlabhq_production; # Grant all privileges on database template1=# GRANT ALL PRIVILEGES ON DATABASE gitlabhq_production to gitlab; # Quit from PostgreSQL server template1=# q # Try connect to new database $ su - gitlab $ psql -d gitlabhq_production -U gitlab
(譯者注:以上3種數據庫根據需要安裝其一即可)
2. 安裝 Ruby
wget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p194.tar.gz tar xfvz ruby-1.9.3-p194.tar.gz cd ruby-1.9.3-p194 ./configure make sudo make install
3. 安裝 Gitolite
為 Git 創建用戶:
sudo adduser --system --shell /bin/sh --gecos 'git version control' --group --disabled-password --home /home/git git
為 GitLab 創建用戶:
# ubuntu/debian sudo adduser --disabled-login --gecos 'gitlab system' gitlab
將 gitlab 用戶添加到 git 用戶組:
sudo usermod -a -G git gitlab
將 git 用戶添加到 gitlab 用戶組:
sudo usermod -a -G gitlab git
生成密鑰:
sudo -H -u gitlab ssh-keygen -q -N '' -t rsa -f /home/gitlab/.ssh/id_rsa
克隆 GitLab 的 Gitolite 分支源代碼:
sudo -H -u git git clone -b gl-v304 https://github.com/gitlabhq/gitolite.git /home/git/gitolite
安裝:
cd /home/git sudo -u git -H mkdir bin sudo -u git sh -c 'echo -e "PATH=$PATH:/home/git/binnexport PATH" >> /home/git/.profile' sudo -u git sh -c 'gitolite/install -ln /home/git/bin' sudo cp /home/gitlab/.ssh/id_rsa.pub /home/git/gitlab.pub sudo chmod 0444 /home/git/gitlab.pub sudo -u git -H sh -c "PATH=/home/git/bin:$PATH; gitolite setup -pk /home/git/gitlab.pub"
權限:
sudo chmod -R g+rwX /home/git/repositories/ sudo chown -R git:git /home/git/repositories/
檢查:退出並重新登錄以使 git 用戶組生效
# 克隆 admin 資源庫以將 localhost 添加到 known_hosts # 並且確認 gitlab 用戶有權訪問 gitolite sudo -u gitlab -H git clone git@localhost:gitolite-admin.git /tmp/gitolite-admin # 如果執行成功,你可以將其刪除 sudo rm -rf /tmp/gitolite-admin
重要! 如果你不能克隆 gitolite-admin 資源庫,請不要繼續本次安裝,請根據 Trouble Shooting Guide 並且確認你已經小心的完成上文的全部步驟。
筆者注:這一步測試能否克隆成功。本人沒有注意這個提示,完成后續安裝后發現怎么都不能通過git@localhost:gitolite-admin.git的方式克隆工程,原因就是ssh認證失敗,所以請務必確認這一點。順便說下本人ssh認證失敗的原因: /etc/ssh/sshd_config配置文件里面PubkeyAuthentication的值為no,意味着不允許公鑰認證,改為yes就可以了。如果還是不能克隆,重復下第3步,並且注意每個命令是否執行成功。或者刪除git和gitlab用戶,重新執行第3步。
4. 克隆 GitLab 源代碼並安裝先決條件
sudo gem install charlock_holmes --version '0.6.8'
sudo pip install pygments
sudo gem install bundler
cd /home/gitlab
# Get gitlab code. Use this for stable setup
sudo -H -u gitlab git clone -b stable https://github.com/gitlabhq/gitlabhq.git gitlab
(2013/1/6,最近發現最新的版本是4.0.0.rc2,這個版本已經沒有支持sqlite,而我選擇sql數據庫的時候沒有成功,
克隆之后執行
sudo -u gitlab git checkout 2.9.1
可以回到2.9.1的版本,這個版本既支持sqlite,其gitlab管理界面也較美觀。3.1.0以后的版本管理界面都有點難看。)
# Skip this for stable setup.(筆者注:執行了上個命令就不用執行這個命令了)
# Master branch (recent changes, less stable)
sudo -H -u gitlab git clone -b master https://github.com/gitlabhq/gitlabhq.git gitlab cd gitlab # Rename config files sudo -u gitlab cp config/gitlab.yml.example config/gitlab.yml
選擇你希望使用的數據庫
# SQLite
sudo -u gitlab cp config/database.yml.sqlite config/database.yml
# Mysql
sudo -u gitlab cp config/database.yml.mysql config/database.yml
# PostgreSQL
sudo -u gitlab cp config/database.yml.postgres config/database.yml
# 修改 config/database.yml 確認輸入了正確的用戶名/密碼
安裝數據庫 gems
# mysql
sudo -u gitlab -H bundle install --without development test sqlite postgres --deployment # 或者 postgres sudo -u gitlab -H bundle install --without development test sqlite mysql --deployment # 或者 sqlite sudo -u gitlab -H bundle install --without development test mysql postgres --deployment
初始化數據庫
sudo -u gitlab bundle exec rake gitlab:app:setup RAILS_ENV=production
設置 GitLab hooks
sudo cp ./lib/hooks/post-receive /home/git/.gitolite/hooks/common/post-receive sudo chown git:git /home/git/.gitolite/hooks/common/post-receive
確認應用程序狀態:
sudo -u gitlab bundle exec rake gitlab:app:status RAILS_ENV=production # OUTPUT EXAMPLE Starting diagnostic config/database.yml............exists config/gitlab.yml............exists /home/git/repositories/............exists /home/git/repositories/ is writable?............YES remote: Counting objects: 603, done. remote: Compressing objects: 100% (466/466), done. remote: Total 603 (delta 174), reused 0 (delta 0) Receiving objects: 100% (603/603), 53.29 KiB, done. Resolving deltas: 100% (174/174), done. Can clone gitolite-admin?............YES UMASK for .gitolite.rc is 0007? ............YES /home/git/share/gitolite/hooks/common/post-receive exists? ............YES
筆者注:如果所有結果都是 YES,恭喜!你可以繼續進行下一步。
5. 設置 web server
應用可以用下一個命令行動:
# 用於測試目的 sudo -u gitlab bundle exec rails s -e production # 用於守護進程 sudo -u gitlab bundle exec rails s -e production -d
默認登錄用戶名及密碼:
筆者注:記住這個用戶名和密碼,在通過瀏覽器登錄gitlab工程主頁的時候有用。
admin@local.host 5iveL!fe
6. 運行 Resque 進程(用於處理工作隊列)
# 手動啟動 sudo -u gitlab bundle exec rake environment resque:work QUEUE=* RAILS_ENV=production BACKGROUND=yes # GitLab 啟動腳本 sudo -u gitlab ./resque.sh # 如果你使用 root 運行此腳本,會導致 /home/gitlab/gitlab/tmp/pids/resque_worker.pid 文件的擁有者為 root # 將導致 resque 在下一次系統初始化中無法啟動
自定義 Resque 使用的 Redis 連接
如果你希望 Resque 連接到一個非標准端口號或另一台服務器上的 Redis,你可以在 config/resque.yml 文件修改連接信息:
production: redis.example.com:6379
好了,我們已經擁有了一個工作正常的 GitLab 了,但請繼續下去,有一些事情是必須完成的。
Nginx 與 Unicorn
1. Unicorn
cd /home/gitlab/gitlab sudo -u gitlab cp config/unicorn.rb.example config/unicorn.rb sudo -u gitlab bundle exec unicorn_rails -c config/unicorn.rb -E production -D
2. Nginx
# 初次安裝 Nginx sudo apt-get install nginx # 添加GitLab 到 nginx sites sudo wget https://raw.github.com/gitlabhq/gitlab-recipes/master/nginx/gitlab -P /etc/nginx/sites-available/ sudo ln -s /etc/nginx/sites-available/gitlab /etc/nginx/sites-enabled/gitlab # 修改 **YOUR_SERVER_IP** 與 **YOUR_SERVER_FQDN** # 為起初的 IP 地址與准備讓 GitLab 服務的域名sudo vim /etc/nginx/sites-enabled/gitlab筆者注:本人最初的時候不知道這個配置文件怎么配置,在瀏覽器里輸入服務器ip的時候老是出現“welcome to nginx”頁面。后來的配置是listion 80; #監聽所有80端口的客戶端請求server_name: 192.168.1.120; #這是我ubuntu服務器的ip地址。因為我們是小組局域網訪問,所以直接配ip地址就可以了。遠程訪問的話可以通過vpn鏈接。# 重啟 nginx:sudo /etc/init.d/nginx restart
3. Init 腳本
在 /etc/init.d/gitlab 創建 init 腳本:
sudo wget https://raw.github.com/gitlabhq/gitlab-recipes/master/init.d/gitlab -P /etc/init.d/
sudo chmod +x /etc/init.d/gitlab
設置 GitLab 自動啟動:
sudo update-rc.d gitlab defaults 21
現在你可以用這種方式啟動/重啟/停止 GitLab 服務:
sudo /etc/init.d/gitlab restart
至此搭建過程全部完成,關於添加用戶和創建工程請參考這篇博文:
http://blog.csdn.net/passion_wu128/article/details/8218041
https://github.com/xiaobozi/gitlab-recipes/blob/master/install/CentOS_6.md
演示地址
Posted in git.
git push : fatal: remote error: You can't push to git 解決辦法
branch正確的情況下,
不知為什么,在push的時候總是出現:
1 |
[root@aikaiyuan ~]# git push |
2 |
fatal: remote error: |
3 |
You can't push to git://github.com/aikaiyuan/python.git |
4 |
Use git@github.com:aikaiyuan/python.git |
1 |
[root@aikaiyuan ~]# git remote rm origin |
2 |
[root@aikaiyuan ~]# git remote add origin git@github.com:aikaiyuan/python.git |
3 |
[root@aikaiyuan ~]# git push origin |
Git錯誤non-fast-forward后的沖突解決
當要push代碼到git時,出現提示:
error:failed to push some refs to …
Dealing with “non-fast-forward” errors
From time to time you may encounter this error while pushing:
- $ git push origin master
- To ../remote/
- ! [rejected] master -> master (non-fast forward)
- error: failed to push some refs to ‘../remote/’
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes before pushing again. See the ‘non-fast forward’
section of ‘git push –help’ for details.
This error can be a bit overwhelming at first, do not fear. Simply put, git cannot make the change on the remote without losing commits, so it refuses the push. Usually this is caused by another user pushing to the same branch. You can remedy this by fetching and merging the remote branch, or using pull to perform both at once.
In other cases this error is a result of destructive changes made locally by using commands like git commit –amend or git rebase. While you can override the remote by adding –force to the push command, you should only do so if you are absolutely certain this is what you want to do. Force-pushes can cause issues for other users that have fetched the remote branch, and is considered bad practice. When in doubt, don’t force-push.
問題(Non-fast-forward)的出現原因在於:git倉庫中已經有一部分代碼,所以它不允許你直接把你的代碼覆蓋上去。於是你有2個選擇方式:
1,強推,即利用強覆蓋方式用你本地的代碼替代git倉庫內的內容
git push -f
2,先把git的東西fetch到你本地然后merge后再push
$ git fetch
$ git merge
這2句命令等價於
- $ git pull
可是,這時候又出現了如下的問題:
上面出現的 [branch “master”]是需要明確(.git/config)如下的內容
[branch “master”]
remote = origin
merge = refs/heads/master
這等於告訴git2件事:
1,當你處於master branch, 默認的remote就是origin。
2,當你在master branch上使用git pull時,沒有指定remote和branch,那么git就會采用默認的remote(也就是origin)來merge在master branch上所有的改變
如果不想或者不會編輯config文件的話,可以在bush上輸入如下命令行:
- $ git config branch.master.remote origin
- $ git config branch.master.merge refs/heads/master
之后再重新git pull下。最后git push你的代碼吧。it works now~
git config push.default matching
昨天學習了Git,今天就鏈接Github試試,操作git push命令,結果卻遇到下面的提示
01 |
$ git push |
02 |
warning: push.default is unset; its implicit value is changing inGit 2.0 from 'matching' to 'simple'. To squelch this messageand maintain the current behavior after the default changes, use: |
03 |
04 |
git config --global push.default matching |
05 |
06 |
To squelch this message and adopt the new behavior now, use: |
07 |
08 |
git config --global push.default simple |
09 |
10 |
See 'git help config' and search for 'push.default' for further information.(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode 'current' instead of 'simple' if you sometimes use older versions of Git) |
11 |
12 |
Everything up-to-date |
這個情況我沒有遇到過,為了謹慎處理,於是網絡之,發現如下解決辦法,下面轉自:偏安一隅
升級到 git 1.6.3 以后,每次 git push 的時候都會出現這樣“嚇人”的警告。
01 |
warning: You did not specify any refspecs to push, and the current remote |
02 |
warning: has not configured any push refspecs. The default action in this |
03 |
warning: case is to push all matching refspecs, that is, all branches |
04 |
warning: that exist both locally and remotely will be updated. This may |
05 |
warning: not necessarily be what you want to happen. |
06 |
warning: |
07 |
warning: You can specify what action you want to take in this case, and |
08 |
warning: avoid seeing this message again, by configuring 'push.default' to: |
09 |
warning: 'nothing' : Do not push anything |
10 |
warning: 'matching' : Push all matching branches (default) |
11 |
warning: 'tracking' : Push the current branch to whatever it is tracking |
12 |
warning: 'current' : Push the current branch |
通常,這是很多 Linux 或者說開源社區貼心的地方,主動告訴你,“注意了,我們發布了一個新版本,有些地方和之前的不太一樣,需要你自己動手改一下”。。。只是,為什么不直接給出一條簡單明了的指令呢?<strong>比如:</strong>
git config push.default current
這樣執行git push的時候,只會push當前的branch,如果設置為matching的話,會push所有的有改動的branch到相應的repository的ref中,相對來說安全性差了點。
另外,我還看到了一篇blog1,講述了10個升級到1.6.3的理由,除了性能和易用性上的改進之外,又學到了幾個新的命令:
- git diff —staged 等同於 git diff —cached
- git checkout – 返回之前的branch,類似bash。
- git log —graph 相當於一個終端版的gitk
- git log —oneline 精簡版的log信息,只有changeset號的前7位和commit信息。
這里我設置如下:
git config --global push.default simple
如果你還想了解更多,可以運行git help config,會彈出git-config幫助頁面,上面有如下介紹:
push.default
Defines the action git push should take if no refspec is given on the command line, no refspec is configured in the remote, and no refspec is implied by any of the options given on the command line. Possible values are:
- nothing – do not push anything.
- matching – push all branches having the same name in both ends. This is for those who prepare all the branches into a publishable shape and then push them out with a single command. It is not appropriate for pushing into a repository shared by multiple users, since locally stalled branches will attempt a non-fast forward push if other users updated the branch.
This is currently the default, but Git 2.0 will change the default to simple.- upstream – push the current branch to its upstream branch. With this, git push will update the same remote ref as the one which is merged by git pull, making push and pull symmetrical. See “branch.<name>.merge” for how to configure the upstream branch.
- simple – like upstream, but refuses to push if the upstream branch’s name is different from the local one. This is the safest option and is well-suited for beginners. It will become the default in Git 2.0.
- current – push the current branch to a branch of the same name.
The simple, current and upstream modes are for those who want to push out a single branch after finishing work, even when the other branches are not yet ready to be pushed out. If you are working with other people to push into the same shared repository, you would want to use one of these.
英文學得不好就不翻譯了,但大體是說simple是最安全的,也非常適合初學者。simple也將是Git2.0的默認值。
希望對你有幫助哈
Posted in git.
Linux 下搭建 Git WEB管理平台
WEB管理平台使用 GitLab
環境需求
- CentOS
- Ruby 1.9.3+
- Mysql
- Git
- Gitolite
- Redis
- Resque
其中Mysql、Git、Redis的安裝不贅述,都可以直接yum安裝
Ruby的安裝
因為CentOS源里的ruby版本太低,我們直接下載源碼進行安裝
安裝之前確認系統中已經安裝了libyaml
沒有的話直接下載源碼安裝
<code> wget http://pyyaml.org/download/libyaml/yaml-0.1.tar.gz tar zxvf yaml-0.1.tar.gz cd yaml-0.1 ./configure make && make install </code>
下載ruby源碼
http://ruby.taobao.org/mirrors/ruby/ruby-1.9-stable.tar.gz
安裝
<code> tar zxvf ruby-1.9-stable.tar.gz cd ruby-1.9-xxxx/ ./configure make && make install </code>
結束
一般情況下安裝會很順利
Gitolite的安裝
創建專屬用戶
<code> useradd -d /home/git -m git </code>
然后用git身份登錄
<code> su git </code>
進入到HOME目錄
<code> cd ~ </code>
下載源碼
直接從Github進行clone
<code> git clone git://github.com/sitaramc/gitolite </code>
進行安裝
<code> mkdir -p $HOME/bin gitolite/install -to $HOME/bin </code>
如果提示Can't locate Time/HiRes.pm in @INC的話執行下面的命令進行類庫安裝
<code> perl -MCPAN -e shell install Time::HiRes </code>
如果提示Can't locate CPAN.pm in @INC的話先使用yum進行安裝yum install perl-CPAN
將bin加入到PATH變量中
編輯~/.profile添加如下內容
<code> export PATH=$PATH:/home/git/bin </code>
GitLab的安裝
創建專屬用戶
<code> useradd -d /home/gitlab -m -g git gitlab </code>
切換至gitlab並進入HOME目錄
依賴的Gems (root身份安裝)
<code> gem install resque gem install charlock_holmes --version '0.6.9' </code>
charlock_holmes 會依賴libicu 可以直接yum安裝yum install libicu-devel
如果提示cannot load such file -- zlib需要安裝zlib庫
<code>yum install zlib-devel # 安裝ruby自帶的zlib.so cd ruby-1.9-xxxx/ext/zlib ruby ./extconf.rb make && make install </code>
下載源碼
<code> git clone git://github.com/gitlabhq/gitlabhq server </code>
站點信息配置
<code> cp server/config/gitlab.yml.example server/config/gitlab.yml cp server/config/unicorn.rb.example server/config/unicorn.rb </code>
因為我們釋放到了server目錄下,需要修改unicorn.rb將第一行的默認目錄修改下
創建satellites目錄
<code> mkdir gitlab-satellites </code>
數據庫配置
<code> cp server/config/database.yml.mysql server/config/database.yml </code>
Redis配置(一般不需要)
<code> cp server/config/resque.yml.example server/config/resque.yml </code>
進行產品發布
<code> cd ~/server bundle install --deployment --without development test postgres </code>
找不到bundle的時候可以執行gem install bundler安裝
配置Git
<code> git config --global user.name "GitLab" git config --global user.email "gitlab@localhost" </code>
配置GitLab的Hooks
<code> # root 權限運行
mkdir -p /home/git/.gitolite/hooks/common
cp /home/gitlab/server/lib/hooks/post-receive /home/git/.gitolite/hooks/common/post-receive
chown git:git -R /home/git/.gitolite
</code>
創建用戶(gitlab)的SSH公匙並導入到gitolite中
執行前確定/home/git/.gitolite/logs目錄存在,否則導入key時會報錯
FATAL: errors found but logfile could not be created
FATAL: /home/git/.gitolite/logs/gitolite-2013-02.log: No such file or directory
FATAL: cli gitolite setup -pk /home/git/gitlab.pub
<code> su gitlab ssh-keygen -t rsa cp ~/.ssh/id_rsa.pub /home/git/gitlab.pub chmod 0444 /home/git/gitlab.pub su git ~/bin/gitolite setup -pk ~/gitlab.pub </code>
關於傳遞了公鑰后依然會要求輸入密碼的情況說明/ssh-keygen后自動驗證無效
如果你無法自動驗證的話先嘗試將/home/git目錄權限設置為755
如果正常了的話就不用看下面這兩條了
- 使用gitolite的setup命令導入key的時候會在
~/.ssh/authorized_keys中添加自定義的command命令,導致/var/log/secure中查看不到ssh自動驗證的錯誤信息(刪除后再嘗試即可) - 執行上面的步驟后如果在secure日志中發現
Authentication refused: bad ownership or modes for directory /home/git的話需要把git目錄權限設置為755
初始化數據庫
- 執行下面的命令之前需要配置了正確的數據庫信息並開啟了Redis
- 需要
/home/git目錄權限為770 - 需要
/home/git/repositories目錄權限為770(沒有的話新創建一個)
執行
<code> cd ~/server bundle exec rake gitlab:setup RAILS_ENV=production </code>
TMD終於好了,讓我們來檢查下gitlab的狀態吧
<code> cd ~/server
# 查看環境信息
bundle exec rake gitlab:env:info RAILS_ENV=production
# 檢查組件依賴(全綠色的話就過了)
bundle exec rake gitlab:check RAILS_ENV=production
</code>
添加管理腳本
從https://raw.github.com/gitlabhq/gitlab-recipes/4-1-stable/init.d/gitlab下載腳本到/etc/init.d/gitlab
然后chmod +x /etc/init.d/gitlab給上執行權限
最后chkconfig --add gitlab加到service列表中,然后chkconfig gitlab on開啟自啟動
安裝結束
使用service gitlab start即可啟動gitlab進程了
如何訪問gitlab的web頁面?
gitlab默認是使用的unix socket訪問,需要nginx進行轉發,配置文件在這里https://raw.github.com/gitlabhq/gitlab-recipes/4-1-stable/nginx/gitlab
不過我們可以修改unicorn.rb來使用TCP方式訪問
修改server/config/unicorn.rb找到listen字段將后面的內容修改成
<code> listen 80 </code>
即可
訪問web后默認帳號為admin@local.host密碼為5iveL!fe
一些錯誤的解決方法
如果/home/gitlab/server/log/githost.log中出現error
ERROR -> Gitolite error -> error: cannot run hooks/post-receive: No such file or directory
並且切換到git用戶后執行env -i redis-cli報錯
解決方法
<code> ln -s /usr/local/bin/redis-cli /usr/bin/ </code>
ERROR -> Gitolite error -> remote: FATAL: git config ‘core.sharedRepository’ not allowed
解決方法
編輯/home/git/.gitolite.rc找到GIT_CONFIG_KEYS將后面的內容修改成'.*',修改后為GIT_CONFIG_KEYS => '.*'



