直接通过如下命令安装即可
[root@localhost git-1.9.3]# yum install git
[root@localhost git-1.9.3]# git --version
git version 1.7.1
- 使用步骤
- 添加git配置信息
[root@localhost src]# git config --global user.name "w***m***"
[root@localhost src]# git config --global user.email wm***@163.cpm
Git的配置信息分为全局和项目两种,上面命令中带了“--global"参数,这就意味是在进行全局配置,它会影响本机上的每个一个Git项目。
查看全局配置信息,可以看到我们配置的用户名和邮箱。
[root@localhost src]# cat ~/.gitconfig
[user]
name = w***m***
email = wm***@163.cpm
[root@localhost src]#
- 创建本地仓储
[wm@localhost ~]$ pwd
/home/wm
[wm@localhost ~]$ mkdir projects
[wm@localhost ~]$ cd projects/
[wm@localhost projects]$ git init
Initialized empty Git repository in /home/wm/projects/.git/
[wm@localhost projects]$ ls -altr .git/
- 产生ssh,并实例下载hadoop-book源码
[wm@localhost projects]$ cd ~/.ssh
[wm@localhost .ssh]$ ls -al
total 8
drwx------. 2 wm wm 4096 May 15 09:04 .
drwx------. 28 wm wm 4096 May 16 12:30 ..
[wm@localhost .ssh]$ ssh-keygen -C wm***@163.com -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/wm/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/wm/.ssh/id_rsa.
Your public key has been saved in /home/wm/.ssh/id_rsa.pub.
The key fingerprint is:
68:67:20:8c:f6:ad:14:f4:58:a7:71:eb:1d:29:b9:20 wmengbeyond@163.com
The key's randomart image is:
+--[ RSA 2048]----+
| . o o |
| + + = o . |
| o E = + o |
| . . = = + . |
| o + S . |
| . o o |
| . |
| |
| |
+-----------------+
[wm@localhost .ssh]$ ls
id_rsa id_rsa.pub
[wm@localhost .ssh]$ cd ..
[wm@localhost ~]$ ls
Desktop Downloads Pictures Public Videos
Documents Music projects Templates
[wm@localhost ~]$ cd projects/
[wm@localhost projects]$ git clone https://github.com/tomwhite/hadoop-book.git
Initialized empty Git repository in /home/wm/projects/hadoop-book/.git/
remote: Reusing existing pack: 3469, done.
remote: Total 3469 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3469/3469), 2.44 MiB | 177 KiB/s, done.
Resolving deltas: 100% (1076/1076), done.
[wm@localhost projects]$ ls
hadoop-book
添加git配置信息源码包安装出现各种异常情况处理,但没有很好地处理,最后通过yum完成,以下是源码过程(无参考价值,以后修改)Git安装依赖curl,zlib,openssl,expat,libiconv 等库的代码,之前通过源码包安装zlib和openssl,这里只安装其他源码包。安装curl
[root@localhost src]# wget http://curl.haxx.se/download/curl-7.36.0.tar.bz2
[root@localhost src]# tar -jxvf curl-7.36.0.tar.bz2
[root@localhost curl-7.36.0]# ./configure --prefix=/usr/local/curl-7.36.0
[root@localhost curl-7.36.0]# make clean
[root@localhost curl-7.36.0]# make && make install
安装 expat,libiconv
[root@localhost curl-7.36.0]# yum install expat-devel gettext-devel
还需要安装perl,省略步骤
[root@localhost src]# wget https://www.kernel.org/pub/software/scm/git/git-1.9.3.tar.gz
[root@localhost src]# tar -zxvf git-1.9.3.tar.gz
[root@localhost src]# cd git-1.9.3
[root@localhost git-1.9.3]# ./configure --help | grep perl
--without-iconv if your architecture doesn't properly support iconv
--with-perl=PATH provide PATH to perl
[root@localhost git-1.9.3]# make clean
[root@localhost git-1.9.3]# ./configure --prefix=/usr/local/git --with-perl=/usr/local/perl-5.18.2/
[root@localhost git-1.9.3]# make && make install
windows下使用git操作实例
在windows下使用git,主要通过命令操作实现,具体在github上创建仓库和ssh keys已省略,假定git已能连接上github。
Welcome to Git (version 1.9.0-preview20140217)
Run 'git help git' to display the help index.
Run 'git help <command>' to display help for specific commands.
Administrator@QT-20140228CYKZ ~
$ cd f:
Administrator@QT-20140228CYKZ /f
$ ls
Administrator@QT-20140228CYKZ /f
$ cd Imgo.MultiGet/
上面的命令主要是进入到目录 Imgo.MultiGet文件夹中。
Administrator@QT-20140228CYKZ /f/Imgo.MultiGet
$ git init
Initialized empty Git repository in f:/Imgo.MultiGet/.git/
Administrator@QT-20140228CYKZ /f/Imgo.MultiGet (master)
$ git add .
Administrator@QT-20140228CYKZ /f/Imgo.MultiGet (master)
$ git commit -m "Imgo.MultiGet"
[master (root-commit) e012e15] Imgo.MultiGet
59 files changed, 7242 insertions(+)
create mode 100644 AutoDownloads/AutoDownloadsExtension.cs
create mode 100644 AutoDownloads/DayHourMatrix.cs
create mode 100644 CalculatedSegment.cs
上面的命令主要是初始化需要提交的文件夹,全部加到仓库中。
Administrator@QT-20140228CYKZ /f/Imgo.MultiGet (master)
$ git remote add origin git@github.com:wmengbeyond/MultiGet.git
Administrator@QT-20140228CYKZ /f/Imgo.MultiGet (master)
$ git push -u origin master
To git@github.com:wmengbeyond/MultiGet.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'git@github.com:wmengbeyond/MultiGet.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Administrator@QT-20140228CYKZ /f/Imgo.MultiGet (master)
$ git push -f
warning: push.default is unset; its implicit value is changing in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the current behavior after the default changes, use:
git config --global push.default matching
To squelch this message and adopt the new behavior now, use:
git config --global push.default simple
When push.default is set to 'matching', git will push local branches
to the remote branches that already exist with the same name.
如果push失败直接通过 git push -f.