Git是一个开源的分布式版本控制系统,用以有效、高速的处理从很小到非常大的项目版本管理. Git 是 Linus Torvalds 为了帮助管理 Linux 内核开发而开发的一个开放源码的版本控制软件,公司目前用的是svn但是总听说git多好多好,今天试着搭建了下,并把中间遇到的错误做了下笔记,以后继续深入

[root@localhost ~]# yum install git
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.yun-idc.com
 * extras: mirrors.yun-idc.com
 * updates: mirrors.yun-idc.com
base                                                                                                         | 3.7 kB     00:00     
extras                                                                                                       | 3.3 kB     00:00     
updates                                                                                                      | 3.4 kB     00:00     
updates/primary_db                                                                                           | 5.3 MB     00:04     
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package git.x86_64 0:1.7.1-3.el6_4.1 will be installed
--> Processing Dependency: perl-Git = 1.7.1-3.el6_4.1 for package: git-1.7.1-3.el6_4.1.x86_64
--> Processing Dependency: perl(Git) for package: git-1.7.1-3.el6_4.1.x86_64
--> Processing Dependency: perl(Error) for package: git-1.7.1-3.el6_4.1.x86_64
--> Running transaction check
---> Package perl-Error.noarch 1:0.17015-4.el6 will be installed
---> Package perl-Git.noarch 0:1.7.1-3.el6_4.1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

====================================================================================================================================
 Package                         Arch                        Version                                Repository                 Size
====================================================================================================================================
Installing:
 git                             x86_64                      1.7.1-3.el6_4.1                        base                      4.6 M
Installing for dependencies:
 perl-Error                      noarch                      1:0.17015-4.el6                        base                       29 k
 perl-Git                        noarch                      1.7.1-3.el6_4.1                        base                       28 k

Transaction Summary
====================================================================================================================================
Install       3 Package(s)

Total download size: 4.7 M
Installed size: 15 M
Is this ok [y/N]: y
Downloading Packages:
(1/3): git-1.7.1-3.el6_4.1.x86_64.rpm                                                                        | 4.6 MB     00:10     
(2/3): perl-Error-0.17015-4.el6.noarch.rpm                                                                   |  29 kB     00:00     
(3/3): perl-Git-1.7.1-3.el6_4.1.noarch.rpm                                                                   |  28 kB     00:00     
------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                               449 kB/s | 4.7 MB     00:10     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : 1:perl-Error-0.17015-4.el6.noarch                                                                                1/3 
  Installing : perl-Git-1.7.1-3.el6_4.1.noarch                                                                                  2/3 
  Installing : git-1.7.1-3.el6_4.1.x86_64                                                                                       3/3 
  Verifying  : git-1.7.1-3.el6_4.1.x86_64                                                                                       1/3 
  Verifying  : perl-Git-1.7.1-3.el6_4.1.noarch                                                                                  2/3 
  Verifying  : 1:perl-Error-0.17015-4.el6.noarch                                                                                3/3 

Installed:
  git.x86_64 0:1.7.1-3.el6_4.1                                                                                                      

Dependency Installed:
  perl-Error.noarch 1:0.17015-4.el6                                perl-Git.noarch 0:1.7.1-3.el6_4.1                               

Complete!



[root@localhost ~]# git --version
git version 1.7.1


[root@localhost ~]# adduser git

[root@localhost data]# mkdir /data/git
[root@localhost data]# cd /data/git/

[root@localhost git]# git init --bare project.git

[root@localhost git]# ls
project.git

[root@localhost git]# cd project.git/
[root@localhost ]# ls
branches  config  description  HEAD  hooks  info  objects  refs

[root@localhost project.git]# vim config 
[receive]
denyCurrentBranch = ignore

执行以上命令 Git命令,会创建一个裸仓库,裸仓库没有工作区,因为服务器上的Git仓库纯粹是为了共享,所以不让用户直接登录到服务器上去改工作区,并且服务器上的Git仓库通常都以.git结尾。

[root@localhost git]# chown -R git.git project.git

[root@localhost git]# cat /etc/passwd|grep git
git:x:501:501:git version manage:/home/git:/bin/bash

[root@localhost git]# vim /etc/passwd
git:x:501:501:git version manage:/home/git:/usr/bin/git-shell

[root@localhost ~]# ssh-keygen -t rsa

[root@localhost ~]# cd .ssh/

[root@localhost ~]# scp id_rsa.pub 192.168.1.204:/root/

server
cat id_rsa.pub >> /home/git/.ssh/authorized_keys

client git clone git@192.168.1.204:/data/git/project.git


git版本冲突
[root@localhost project]$ git stash //缓存起来
Saved working directory and index state WIP on master: 944b9a5 204
HEAD is now at 944b9a5 204
[root@localhost project]$ git pull origin // 分支
Address 192.168.1.204 maps to localhost, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT!
Updating 944b9a5..393a596
Fast-forward
 c.txt |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
[root@localhost project]$ git stash pop	//还原
Auto-merging c.txt
CONFLICT (content): Merge conflict in c.txt
[root@localhost project]$ git stash clear 


[root@localhost project]$ git push
No refs in common and none specified; doing nothing.  
Perhaps you should specify a branch such as 'master'.  
fatal: The remote end hung up unexpectedly  
error: failed to push some refs to 'git@192.168.1.204:/data/git/project.git'  

解决办法:git push origin master