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 [email protected]:/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 '[email protected]:/data/git/project.git' 解決辦法:git push origin master