git ,创建生成 making git-svn work on mac tiger

 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.6
mike@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

 

Posted in gitsvn.

Git冲突:commit your changes or stash them before you can merge. 解决办法

用git pull来更新代码的时候,遇到了下面的问题:

1error: Your local changes to the following files would be overwritten by merge:
2    xxx/xxx/xxx.php
3Please, commit your changes or stash them before you can merge.
4Aborting

出现这个问题的原因是其他人修改了xxx.php并提交到版本库中去了,而你本地也修改了xxx.php,这时候你进行git pull操作就好出现冲突了,解决方法,在上面的提示中也说的很明确了。

1、保留本地的修改 的改法

1)直接commit本地的修改

2)通过git stash

1git stash
2git pull
3git 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、放弃本地修改 的改法

1git reset --hard
2git pull

Posted in commitgit解决错误.

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 => ‘.*’

Posted in centosgitruby.

加快 git clone 速度的方法

git clone 可以不用全部下载,只下载当前的 commit 版本,

1git 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上提交时就不用重复输入用户名密码了

Posted in bashgitsvn.

Git 取消跟踪已版本控制的文件

Git 是一个很好的版本控制工具,当然驾驭起来相比 SVN 要稍微复杂一些。初入 Git,难免有一些问题。比如我们不小心将某个文件加入了版本控制,但是突然又不想继续跟踪控制这个文件了,怎么办呢?

其实方法也是很简单的。使用git update-index 即可。

不想继续追踪某个文件

1git update-index --assume-unchanged your_file_path

如果想再次继续跟踪某个文件

1git 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 +0800

init

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 rebase

git 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 show

git 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

一、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
2origin

使用-v选项,可以参看远程主机的网址。

1$ git remote -v
2origin  git@github.com:jquery/jquery.git (fetch)
3origin  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
3jQuery

上面命令表示,克隆的时候,指定远程主机叫做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
2origin/<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也允许手动建立追踪关系。

1git 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启动脚本的替换。

目前遗留问题:

  1. 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”
  2. 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

 

 

Posted in git代码.

linux git 客户端 smartgit

本机装了双系统centos6.5,在centos下装了一套开发环境,发现linux下的git图形客户端好少,能用的更少。本想装一下gitg的,发现gitg要求的依赖包好新,centos基本上不能满足,如果非要用的话,要手动更新好多包,太麻烦。在centos下,推荐使用smartgit。

 

一,下载linux版smartgit

下载地址:http://www.syntevo.com/smartgithg/download

二,安装git

  1. # yum install git  

三,生成公钥和私钥

  1. # ssh-keygen -t rsa -C “你的邮箱”  
  2.   
  3. [zhangying@localhost .ssh]$ pwd   //默认是在~/.ssh目录下  
  4. /home/zhangying/.ssh  
  5.   
  6. [zhangying@localhost .ssh]$ ls  
  7. 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根本无法识别。

看一下效果图:

smartgit

Posted in git.

git项目同时支持多个远端仓库

为了防止github被墙,最好在国内的托管商做一个备份,这就需要同时提交到多个远端仓库,例如一个open source项目同时要提交csdn和github,url分别是

  1. git@github.com:lutaf/auto-complete.git
  2. git@code.csdn.net:lutaf/autocomplete.git

方法很简单,一共分4步

第一步:添加remote信息

  1. git remote gh git@github.com:lutaf/auto-complete.git
  2. git remote cn git@code.csdn.net:lutaf/autocomplete.git

第二步:为每个仓库建立单独的分支

  1. git checkout -b github
  2. ...
  3. git checkout -b csdn

第三步:在各自分支上完成开发,并提交

第四步:把本地分支推送到远端仓库的master分支

  1. git checkout csdn
  2. git 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用户的映射文件,文件格式如下:

1cat /tmp/userinfo.txt
2david=sfzhang<shifeng_zhang88@163.com>
3yanni=yanni<yanni_liu88@163.com>

3.通过git svn clone克隆一个git版本库,SVN里面包含trunk,branchestags

1git 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 查看项目提交的历史记录,包括作者,日照,和提交注释信息等。

1cd yanzi
2git log
3commit 3c4907782804096ea3fa3fb5419dcce610e56f1f
4Author: david <shifeng_zhang88@163.com>
5Date:   Fri May 10 10:27:50 2013 +0000

5.git版本库里面tag都是branches(分支),首先列出当前所有的分支。

1cd yanzi
2git 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

1git tag mobile_1.0.0 tags/mobile_1.0.0
2git tag mobile_1.0.1 tags/mobile_1.0.1

7.将多余的branches删除掉

1git branch -r -d tags/mobile_1.0.0
2Deleted remote branch tags/mobile_1.0.0 (was d50002b).
3git branch -r -d tags/mobile_1.0.1
4Deleted remote branch tags/mobile_1.0.1 (was e7b78a2).

8.再次列出当前的所有分支。

1git branch -r
2  trunk
3  yanziios1.0.1-build-2223-branch-002

9.建立git仓库并初始化版本库。

1mkdir -p /data/gitdata/yanziios.git
2cd /data/gitdata/yanziios.git/
3git init --bare
4Initialized empty Git repository in /data/gitdata/yanziios.git/

10.yanziios.git的属主修改为git用户。

01chown git yanziios.git -R
02ls -l yanziios.git/
03total 64
04drwxr-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
08drwxr-xr-x 2 git root 4096 May 22 12:25 hooks
09drwxr-xr-x 2 git root 4096 May 22 12:25 info
10drwxr-xr-x 4 git root 4096 May 22 12:25 objects
11drwxr-xr-x 4 git root 4096 May 22 12:25 refs

11.添加远程git服务器地址

1git remote add origin git@192.168.1.245:/data/gitdata/yanziios.git

 

12.用git push命令推送全部的分支和标签信息到git服务器上面。

1git 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导出方法。
1git 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.gitbranch  test-build-1442-branch-001 test-001
  • 更多的错误详见making git-svn work on mac tiger

Posted in gitsvn迁移.

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里加入:

XML/HTML代码
1[pack]
2threads = 1
3deltaCacheSize = 128m
4packSizeLimit = 128m
5windowMemory = 128m
6[core]
7packedGitLimit = 128m
8packedGitWindowSize = 128m
如果这个大小你觉得还不够。你还可以更调大一点。这回就没大事喽。

 

 

Posted in git.

git 同时提交到多个版本库

如果你维护了多个git在线平台的版本库,你就会遇到,如何将一份代码在push的时候推到所有的版本库呢?

其实命令行就可以了:

 

XML/HTML代码
1git remote add origin git@git.aikaiyuan.com:git/code.git
有几条就执行几次。最后:git push -u origin  master即可。
 
参考:
  1. http://segmentfault.com/q/1010000000367632
  2. 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 发生了冲突。有两个解决方案:

  1. 把 svn 降级到 1.7.9,一劳永逸。
  2. 使用 git svn dcommit -C1 -l1 来提交。这样会关闭 git 的重命名检测机制,这次提交会丢失重命名操作,取而代之的是一次 remove 和 一次 add 操作,就和 svn 1.4 一样。
 

Posted in gitsvn错误.

在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.

Posted in apachegitLinux.

在 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了。
首先,会看到如下所示的登陆界面:
130610060563703

通过上面提示信息内的账号密码登陆,登陆过后首先新增一个Project:
130610060563702

添加Project过后,会有一个配置向导,提供了非常详细的本地Git配置步骤:
130610060563704

在进行这些本地配置之前,首先要在本地生成SSH-Keygen,并将Public Key添加到GitLab中:

# ssh-keygen -t rsa
# cat .ssh/id_rsa.pub

然后将所查看到的信息,都添加到GitLab的 MyProfile – SSH Key – Add New 中:
130610060563701

接着,就可以再本地按照图片中所示的步骤进行操作并使用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相同。

Posted in centosgit.

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的,其他版本的可以去网上搜,就地址不一样。

1rpm -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位,你懂得

编译安装

1make && 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
sudo  -u gitlab  cp  config /database .yml.postgresql config /database .yml

安装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
sudo  -u gitlab -H bundle  install  --deployment --without development  test  mysql

额外设置

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

截图 gitlab

附注

如果你的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

参考

  1. Installing GitLab with gitolite on CentOS 6.2 and 6.3
  2. 官方Ubuntu安装文档
  3. RedHat/CentOS 安装gitlabhq

 

Posted in gitLinux.

centos安装gitlab

最近换了公司,在交接公司,所以很忙也没有时间写博客,同时随着能力的逐渐提升,很多知识感觉很简单,也没有必要专门写博客,只是把遇到的情况与解决方法写入到了笔记里,正好现在没什么事,就把我最近研究的gitlab如何在centos里安装的笔记分享给大家。

先给大家介绍一下gitlab

GitLab 是一个用于仓库管理系统的 开源项目。使用Git作为代码管理工具,并在此基础上搭建起来的web服务。
应用特点:
1. Web框架使用 Ruby on Rails
2. 基于 MIT代码发布协议。
3. 需要gitolite协同工作。
安装GitLab的需求:
Ubuntu/Debian(推荐这2个系统,也可以安装到CentOS系统中,并且在GitHub上有CentOS的GitLab一键安装脚本)

官方推荐的是那2个系统,但我这里需要安装在centos里,所以没办法自己多研究与测试,总结的安装经验如下:

前置要求

一定要先关闭iptable与selinux

本文安装的系统为centos 6.2 64位系统,安装在dell r410机器

1、安装epel与基础依赖库及软件

1cd /tmp
3rpm -Uvh epel-release-6-8.noarch.rpm
4yum 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
2、安装ruby(一般默认安装都是1.8的,官方要求1.9以上)
01mkdir /tmp/ruby && cd /tmp/ruby
02curl --progress http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p392.tar.gz | tar xz
03cd ruby-1.9.3-p392/
04./configure
05make
06make install
07gem install bundler
08ln -s /usr/local/bin/ruby /usr/bin/ruby
09ln -s /usr/local/bin/gem /usr/bin/gem
10ln -s /usr/local/bin/bundle /usr/bin/bundle
3、创建一个git用户供GitLab使用
1adduser --comment 'GitLab' git
2chmod –R 755 /home/git
4、安装gitlab 的shell
01# Login as git
02sudo su git
03# Go to home directory
04cd /home/git
05# Clone gitlab shell
07cd gitlab-shell
08# switch to right version
09git checkout v1.3.0
10cp config.yml.example config.yml
11# Edit config and replace gitlab_url
12# with something like 'http://domain.com/'
13vim config.yml
14# Do setup
15./bin/install
5、建立gitlab数据库并授权
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)
04mysql> CREATE USER 'gitlab'@'localhost' IDENTIFIED BY 'gitlab';
05# Create the GitLab production database
06mysql> 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.
08mysql> 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
6、克隆gitlab源
01# Clone GitLab repository
02cd /home/git
03sudo -u git -H git clone https://github.com/gitlabhq/gitlabhq.git gitlab
04# Go to gitlab dir
05cd /home/git/gitlab
06# Checkout to stable release
07sudo -u git -H git checkout 5-1-stable
08Configure it
09cd /home/git/gitlab
10# Copy the example GitLab config
11sudo -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
14sudo -u git -H vim config/gitlab.yml
15# Make sure GitLab can write to the log/ and tmp/ directories
16sudo chown -R git log/
17sudo chown -R git tmp/
18sudo chmod -R u+rwX  log/
19sudo chmod -R u+rwX  tmp/
20# Create directory for satellites
21sudo -u git -H mkdir /home/git/gitlab-satellites
22# Create directories for sockets/pids and make sure GitLab can write to them
23sudo -u git -H mkdir tmp/pids/
24sudo -u git -H mkdir tmp/sockets/
25sudo chmod -R u+rwX  tmp/pids/
26sudo chmod -R u+rwX  tmp/sockets/
27# Create public/uploads directory otherwise backup will fail
28sudo -u git -H mkdir public/uploads
29sudo chmod -R u+rwX  public/uploads
30# Copy the example Puma config
31sudo -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
34sudo -u git -H git config --global user.name "GitLab"
35sudo -u git -H git config --global user.email "gitlab@localhost"
7、配置gitlab数据库
1sudo -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
2sudo -u git vim config/database.yml
3Make sure to update username/password in config/database.yml.

这个数据库的账户与密码是在第5步那里创建的。

8、安装gem

1cd /home/git/gitlab
2sudo gem install charlock_holmes --version '0.6.9.4'
3sudo -u git -H bundle install --deployment --without development test postgres

9、启动redis

1/etc/init.d/redis start

10、对数据库进行初始化

1sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production

11、下载启动脚本

1Download the init script (will be /etc/init.d/gitlab):
2sudo 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
3sudo chmod +x /etc/init.d/gitlab
4Make GitLab start on boot:
5chkconfig --add gitlab

12、检测应用状态

01Check if GitLab and its environment are configured correctly:
02sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production
03To make sure you didn't miss anything run a more thorough check with:
04sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production
05If all items are green, then congratulations on successfully installing GitLab! However there are still a few steps left.
06出现了Running? ... no
07Try fixing it:
08sudo -u git -H bundle exec rake sidekiq:start RAILS_ENV=production
09For more information see:
10doc/install/installation.md in section "Install Init Script"
11see log/sidekiq.log for possible errors
12Please 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

1sudo service gitlab start

14、下载nginx(我选nging作为web服务器)

1yum install nginx

15、下载官方提供gitlab的虚拟配置文件,并修改配置

01Download an example site config:
02sudo 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
03Make 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;
08sudo vim /etc/nginx/conf.d/gitlab
09cd /etc/nginx/conf.d
10mv default.conf default.conf.bak
11mv gitlab default.conf
12Restart
13sudo service nginx restart

16、登陆你在nginx里添加的ip,然后输入账户与密码,默认为

1admin@local.host
25iveL!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
# 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

演示地址

http://demo.gitlab.com/users/sign_in

Posted in git.

git push : fatal: remote error: You can't push to git 解决办法

branch正确的情况下,

不知为什么,在push的时候总是出现:

1[root@aikaiyuan ~]# git push
2fatal: 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
 

Posted in errorgit.

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:

  1. $ git push origin master
  2. To ../remote/
  3.  ! [rejected]        master -> master (non-fast forward)
  4. 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.

1334803176_7047

问题(Non-fast-forward)的出现原因在于:git仓库中已经有一部分代码,所以它不允许你直接把你的代码覆盖上去。于是你有2个选择方式:

1,强推,即利用强覆盖方式用你本地的代码替代git仓库内的内容

git push -f

2,先把git的东西fetch到你本地然后merge后再push

$ git fetch

$ git merge

这2句命令等价于

  1. $ git pull

可是,这时候又出现了如下的问题:

1334803661_1873

上面出现的 [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上输入如下命令行:

  1. $ git config branch.master.remote origin
  2. $ git config branch.master.merge refs/heads/master

之后再重新git pull下。最后git push你的代码吧。it works now~

 

Posted in errorgit.

git config push.default matching

昨天学习了Git,今天就链接Github试试,操作git push命令,结果却遇到下面的提示

01$ git push
02warning: 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 
06To squelch this message and adopt the new behavior now, use:
07 
08  git config --global push.default simple
09 
10See '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 
12Everything up-to-date

这个情况我没有遇到过,为了谨慎处理,于是网络之,发现如下解决办法,下面转自:偏安一隅

升级到 git 1.6.3 以后,每次 git push 的时候都会出现这样“吓人”的警告。

01warning: You did not specify any refspecs to push, and the current remote
02warning: has not configured any push refspecs. The default action in this
03warning: case is to push all matching refspecs, that is, all branches
04warning: that exist both locally and remotely will be updated.  This may
05warning: not necessarily be what you want to happen.
06warning:
07warning: You can specify what action you want to take in this case, and
08warning: avoid seeing this message again, by configuring 'push.default' to:
09warning:   'nothing'  : Do not push anything
10warning:   'matching' : Push all matching branches (default)
11warning:   'tracking' : Push the current branch to whatever it is tracking
12warning:   '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的理由,除了性能和易用性上的改进之外,又学到了几个新的命令:

  1. git diff —staged 等同于 git diff —cached
  2. git checkout – 返回之前的branch,类似bash。
  3. git log —graph 相当于一个终端版的gitk
  4. 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 &amp;&amp; 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 &amp;&amp; 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 &amp;&amp; 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 => '.*'

Posted in gitLinuxweb.

转载于:https://www.cnblogs.com/aersliing/p/4214615.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值