如何在windows下安装GIT

Python07

如何在windows下安装GIT,第1张

本文在Windows7下测试成功。

安装和设置Git

下载Git for

Windows,采用默认安装,安装完成后就可以在本地使用Git了。

但要将内容放到Github上,必须先在Github网站上注册个账户,然后在本机使用Git创建SSH Key。操作如下:

在Git Bash上输入命令:

ssh-keygen -C "[email protected]" -t rsa

Note: “[email protected]”需要更换成你在Github上注册的Email地址或者是Username

这样会在用户目录(C:\Users\用户名)下产生一个.ssh文件夹,里面为对应的SSH

Keys,其中id_rsa.pub是Github需要的SSH公钥文件。

到c:\Users\用户名\.ssh\目录找到id_rsa.pub(可能位置不一定对,但是确认是以.pub结尾的文件),并用记事本打开复制全部内容。

Note:建议私钥公钥的名称最好写成"id_rsa",这样连接Github的时候会找这个文件,如果文件名已定,之后改名也行。

在github网站选择“Account Settings”>>“SSH Public Keys”>>“Add another

public key”,将刚才复制的内容粘贴到key文本框内。

这样就可以直接使用Git和GitHub了。

Note:建议在Git Bash中输入“ssh -v [email protected]”测试能够正常连接github

安装Ruby环境

下载RubyInstaller和DevKit。

因为Octopress需要的Ruby版本为1.9.2,所以选rubyinstaller-1.9.2-p290.exe,DevKit-tdm-32-4.5.2-20111229-1559-sfx.exe。

先安装RubyInstaller,然后解压缩DevKit(路径中不能有中文)。

在“Start Command Prompt with Ruby”命令行中进入DevKit解压缩的目录,然后运行以下命令:

ruby dk.rb init

ruby dk.rb install

gem install rdiscount --platform=ruby

如果安装成功,就可以使用一些Ruby的工具了,也为后面搭建博客提供了基础环境。

安装Octopress

先通过Git从Github上克隆一份Octopress(在Git Bash上输入命令)

git clone git://github.com/imathis/octopress.git octopress

然后安装一些依赖的工具(后面都是在Start Command Prompt with Ruby中输入)

cd octopress

ruby --version # Should report Ruby 1.9.2

gem install bundler

bundle install

安装Octopress默认的Theme

rake install

配置Octopress

将octopress的文件夹下的_config.yml的编码改成UTF-8:

保存(或另存为)时选择编码格式为UTF-8

修改_config.yml,批改url、title、subtitle、author等等。

到Ruby的安装目次\lib\ruby\gems\1.9.1\gems\jekyll-0.11.2\lib\jekyll\找到convertible.rb这个文件,批改self.content

= File.read(File.join(base, name))为self.content = File.read(File.join(base,

name), :encoding =>"utf-8")。

写博文

最简单的方式:复制octopress\source\_posts下某个文件,例如2012-07-30-the-first-post.markdown,修改文件名和文件中的内容

或者,命令行中输入rake

new_post["title"],会创建一个新的Post,新文件在source/_post下,文件名如下面的格式:2012-07-31-title.markdown。该文件可以直接打开修改。

写文章时,可以使用Markdown和Octopress

Plugins等工具对内容进行格式排版。

预览效果

在修改设置或者写完文章后,想看看具体效果,可以通过如下命令来完成:

rake generate

rake preview

将博客部署到Github上

在预览的效果符合自己的预期后,就可以通过如下命令将内容部署到Github上了。

如果是第一次部署,需要在Github上创建一个username.github.com的repository

在github网站选择“Create a New Repo”,如图

填写对应的内容即可

note:Repository

name填写username.github.com,username一定要和github的username一致,建好的博客代表的是你这个github账户的主页即page

配置octopress与github的连接:

进入Octopress目录:

rake setup_github_pages

按照提示填入你的github项目网址,比如:

[email protected]:Username/yourname.github.com.git

note:可以按照上面的修改,也可以在github的项目页中找地址

分发到github上:

rake deploy

第一次运行时,会询问是否建立对github的授权,输入:yes。然后将站点更新的内容推送到github上。

补充一点:

最后的但并不是最重要的,我们需要将修改的日志同步到github上,因此下面的3个命令也是必须的。

git status

git add .

git commit -m 'your message'

git push origin source

大功告成!

CentOS默认开启了SELinux,安装Redmine、apache、svn之类的还是蛮复杂的,经过几次折腾之后,终于顺利将redmine折腾成功了,有些心得记录下来备查:

集成方案大体为:

a)

svn和apache集成,通过http协议访问svn,svn使用域名svn.test.com,仓库访问路径为:http://svn.test.com/XXXX

b)

svn通过Perl和redmine的数据库集成提供身份和权限认证,仓库访问用户名和密码由redmine中创建的用户和密码访问,可访问项目仓库受redmine控制

c) redmine用mongrel_rails 运行于3000端口

d) apache使用proxy模块将pms.image-pro.com.cn的80端口反向代理到redmine的3000端口

e) 每5分钟通过cron的形式将redmine中项目信息同步到svn中

1、不要使用passenger集成Apache,使用反向代理方式集成Apache

官方指南中使用passenger来和Apache集成,但是passenger跟SELinux集成是很困难正常运行的,解决办法需要将SELinux更改为permissive模式(编辑

/etc/sysconfig/selinux文件修改为SELINUX=permissive),然而使用Apache的反向代理向rails转发却简单得多。

这种方式需要开启redmine的“启用用于版本库管理的Web

Service”功能,设置方式为安装完成之后,用admin账号登陆redmine,进入“管理”->“配置”->“版本库”设置页面开启“启用用于版本库管理的Web

Service”选项,并生成一个API Key,这个API key有用。

相关virtualhost配置节点如下:

<VirtualHost *:80>

ServerAdmin [email protected]

DocumentRoot "/var/www/redmine"

ServerName pms.test.com

ErrorLog "logs/pms.test.com-error.log"

CustomLog "logs/pms.test.com-access.log" combined

<Location /sys>

Order deny,allow

Allow from 127.0.0.1

Deny from all

</Location>

ProxyPass / http://localhost:3000/

ProxyPassReverse / http://localhost:3000/

</VirtualHost>

注意:如果/etc/hosts文件中没有解析相关域名到127.0.0.1的话,最好在Allow from后面添加一行让服务器ip可以正常访问。

2、使用两个virtualhost,分别安装redmine和svn,并使用一个location配置svn

这样的好处是明显的,svn单独访问也足够间接,不使用svn和svn-private两个Location配置来分别供给SVN客户端和redmine使用。

相关virtualhost配置节点如下:

<VirtualHost *:80>

ServerAdmin [email protected]

ServerName svn.test.com

ErrorLog "logs/dummy-svn.test.com-error.log"

CustomLog "logs/dummy-svn.test.com-access.log" combined

PerlLoadModule Apache2::Redmine

<Location />

DAV svn

SVNParentPath "/var/svn"

Order deny,allow

Deny from all

Satisfy any

PerlAccessHandler Apache::Authn::Redmine::access_handler

PerlAuthenHandler Apache::Authn::Redmine::authen_handler

AuthType Basic

AuthName "Redmine SVN Repository"

#read-only access

<Limit GET PROPFIND OPTIONS REPORT>

Require valid-user

Allow from 127.0.0.1

# Allow from another-ip

Satisfy any

</Limit>

# write access

<LimitExcept GET PROPFIND OPTIONS REPORT>

Require valid-user

</LimitExcept>

## for mysql

RedmineDSN "DBI:mysql:database=redminehost=localhost"

RedmineDbUser "redmine"

RedmineDbPass "password"

</Location>

</VirtualHost>

这里Allow

from跟上面说的一样,最好添加服务器的ip通过,这样一个Location节点即可完成SVN设置,保证redmine中看到的svn仓库地址和SVN客户端(例如:TortoiseSVN)中使用的svn仓库地址一致(都是http://svn.test.com/XXXXX,而不是一个/svn-private/XXX,一个/svn/XXXX),而且svn仓库地址也够简洁。

3、如果邮件使用GMail的服务,则需要使用ruby 1.8.7,rails要求2.3.5

如果默认安装的是ruby 1.8.6则发送邮件的时候会报错,要求先自行starttls命令。必须升级到1.8.7

相关命令:

ftp ftp.ruby-lang.org

cd /pub/ruby

get ruby-1.8.7.pXXX.tar.gz

tar zxvf ruby-1.8.7.pXXX.tar.gz ruby-1.8.7.pXXX

cd ruby-1.8.7.pXXX

./configure --prefix=/usr

make

make install

ruby -v

which ruby

cd ..

这里XXX是对应的发布版本号,当前是330,需要注意的是有些版本不一定能够正常编译通过,我在测试的时候p160编译就通过不了。

4、相关SELinux权限设置

执行以下命令赋予相关目录正确的SELinux属性:

chcon -u system_u -R -t httpd_log_t /var/www/redmine/log

chcon -u system_u -R -t httpd_tmpfs_t /var/www/redmine/tmp

chcon -u system_u -R -t httpd_sys_script_rw_t /var/www/redmine/files

chcon -u system_u -R -t httpd_sys_script_rw_t /var/www/redmine/public/plugin_assets

由于svn版本库的SELinux设置比较复杂,可以通过以下命令直接处理完毕

chcon -u system_u -R -h -t httpd_sys_script_rw_t /var/svn

5、redmine跟svn之间有关版本库通过可以通过cron来完成

cron执行内容如下:

0,5,10,15,20,25,30,35,40,45,50,55 * * * * /usr/bin/ruby /var/www/redmine/extra/svn/reposman.rb --redmine pms.test.com -k apikey --svn-dir /var/svn --owner apache --url http://svn.test.com/ >>/var/log/reposman.log

其中apikey内容为redmine后台生成的API key,这样每5分钟都会将redmine中的版本库信息同步到svn中(自动创建版本库)

6、redmine使用mongrel自启动

安装mongrel之后,使用cron来确保在启动时候自动启动mongrel_rails来启动redmine。

cron执行内容如下:

@reboot cd /var/www/redminerm -f log/mongrel.pid/usr/bin/mongrel_rails start -p 3000 -d -e production

7、使用ImageMagick绘制甘特图,需要rMagick 1.5.17版本

执行以下命令:

yum install ImageMagick -y

yum install ImageMagick-devel -y

yum install freetype -y

yum install gd-devel -y

wget http://www.osresources.com/files/centos-windows-fonts/msfonts.tbz

mkdir /usr/share/fonts/default/TrueType

tar xvjpf msfonts.tbz -C /usr/share/fonts/default/TrueType/

gem install rmagick -v=1.15.17

8、Redmine.pm存放文字需要根据实际情况来定

x64位操作系统perl库文件位置是/usr/lib64/perl5下,perl5.10版本库位置不再是/perl5.8.8,最后位置也不一定是Apache目录,例如:我机器上就是复制到/usr/lib64/perl5/Apache2目录下,所以具体目录应该根据实际情况决定,拷贝完毕之后Apache的相关VirtualHost配置加载的模块语句就有变化了(如上我的变成了Apache::Redmine)。

整体来说,安装过程需要仔细,特别是SELinux在某种程度上来说是设置的羁绊,但RedHat等公司开发它肯定有他的安全必要性,所以我们还是完成SELinux环境下安装比较好。

转载仅供参考,版权属于原作者。祝你愉快,满意请采纳哦

当看到# Thank you for using RVM! 这样的文字时说明rvm 安装完成 

rvm执行前需 source /etc/profile.d/rvm.sh

若提示找不到公钥,执行下边语句,然后重新执行

若提示curl 未找到命令,执行下边语句

查询已经安装的ruby    rvm list                    

列出已知的ruby版本    rvm list known

安装一个ruby版本        rvm install 1.9.3      

卸载一个已安装版本    rvm remove 1.9.2