git--分布式版本管理器的安装 和 使用

GIT在Window上安装很简单,随便搜一个文档就可以,就不叙述了。

GIT在Linux上的安装和使用简介

 
GIT最初是由Linus Benedict Torvalds为了更有效地管理Linux内核开发而创立的分布式版本控制软件,与常用的版本控制工具如CVS、Subversion不同,它不必服务器端软件支持,速度和效率也有着相当程度的提高。

如果拥有CVS或者SVN的使用背景,那么更熟悉的方法是客户端-服务器端模式,所有的文件仓库(repository)都是存放在服务器上的,用户需要在本地安装客户端去服务器上的项目中获取旧版本,提交新版本。
 
GIT抛弃了这种模式,当用户从远端GIT仓库 下载一个工程(project)时,这个工程的所有文件,包括版本历史,文件改动都会下载下来,这时 候本地GIT就演变成了一个服务器,所有的提交(check-in)、提出(check-out)都会在这个本地服务器上执行,当你确定一项修改之后,可 以再和远端仓库进行合并和同步(merge)。所以,GIT的安装和配置步骤无论在本机还是服务器上都是完全一样的。
 
这里简单地介绍GIT在Linux上的安装和使用,算做一个新手入门的简单教程。另外,GIT是有Windows上的客户端的。
1、下载和安装GIT
从这里 http://git-scm.com/download 下载GIT或者使用wget命令获取
 
$ cd
$ wget http://kernel.org/pub/software/scm/git/git-1.7.6.tar.bz2
 
以上地址若是无法下载到的话,请到http://download.csdn.net/detail/lovejuan007/3713236 下载
 
解压后切换到其目录

$ tar xvfj git-1.7.6.tar.bz2  //版本可以自己选择 一样的安装
$ cd git-1.7.6
 
使用默认配置进行安装,如果想修改配置,可以使用 ./configure --help 来获取帮助
 
$ ./configure
$ make
$ make install
 
2、初始化配置
GIT默认安装在 /usr/local/bin ,安装之后可以验证一下是否安装好
 
$ whereis git
git: /usr/local/bin/git
$ git  --version
git version 1.7.6
$ git  --help
 
首先需要指定用户名和电子邮件地址
 
$ git config  --global user.name “GIT Admin”
$ git config  --global user.emal obugs.net@gmail.com
 
再验证一下配置信息

$ git config  --list
user.name=GIT Admin
user.email=obugs.net@gmail.com
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
 
其实这些配置是存放在个人主目录下的 .gitconfig 文件中的
 
$ cat ~/.gitconfig
[user]
name = GIT Admin
email = obugs.net@gmail.com
 
3、建立工程
本地存储的任何一个目录都可以建立GIT工程,如果已有工程位于 /home/obugs/projects/orangebugs 目录,就可以把这目录定义为GIT工程
$ cd /home/obugs/projects/orangebugs
$ git init
Initialized empty Git repository in /home/obugs/projects/orangebugs/.git/
 
这样就建立了一个名为 .git 的文件夹,这就是GIT用来存储信息和跟踪改动的文件夹。

$ ls -altr .git
total 40
drwxrwxr-x 4 git git 4096 Aug 13 22:39 refs
drwxrwxr-x 4 git git 4096 Aug 13 22:39 objects
drwxrwxr-x 2 git git 4096 Aug 13 22:39 info
drwxrwxr-x 2 git git 4096 Aug 13 22:39 hooks
-rw-rw-r -- 1 git git 23 Aug 13 22:39 HEAD
-rw-rw-r -- 1 git git 73 Aug 13 22:39 description
-rw-rw-r -- 1 git git 92 Aug 13 22:39 config
drwxrwxr-x 2 git git 4096 Aug 13 22:39 branches
drwxrwxr-x 36 git git 4096 Aug 13 22:39 ..
drwxrwxr-x 7 git git 4096 Aug 13 22:39 .
 
4、向工程添加和提交文件
这些动作和CVS、SVN等操作类似
 
$ git add *.java *.c
$ git commit -m ‘Initial upload of the project’
create mode 100755 Orangebugs.java
create mode 100755 pwm/ui/DataManager.java
create mode 100755 pwm/ui/PasswordFrame.java
create mode 100755 pwm/tools/StrongEncryption.java
create mode 100755 pwm/tools/PasswordStrength.java
..
 
注意如果之前没有使用 git config 指定用户名和电子邮件地址,这里会报错
$ git commit -m ‘Initial upload of the project'
 
*** Please tell me who you are.
  
Run
 
git config  --global user.email “you@example.com”
git config  --global user.name “Your Name”
 
to set your account’s default identity.
Omit  --global to set the identity only in this repository.
 
fatal: empty ident not allowed
 
5、更改文件和提交改动
编辑文件、添加或者删除了一些字段
$ vi Orangebugs.java
 
查看和GIT仓库中的文件相比有了那些改动
 
$ git diff
diff  --git a/Orangebugs.java b/Orangebugs.java
index 6166ed1..fd82d32 100644
— a/Orangebugs.java
+++ b/Orangebugs.java
@@ -2,7 +2,7 @@
- public counter=10
+ public counter=55
 
如果要提交,需要先确保将文件添加到了临时区域(staging area)然后才能提交,提交时会自动打开 系统的默认编辑器,用户添加一些注释后保存并退出编辑器的时候,这些注释就同时提交到仓库中去了
 
$ git add Orangebugs.java
$ git commit
[master 80f10a9] Added password strength meter functionality
1 files changed, 56 insertions(+), 7 deletions(-)
或者,简单一点的方法是使用 git commit -a 把上面两个命令合二为一。
6、查看状态和查看注释
如果本地的文件和远端GIT仓库上的文件相比没有任何改动,则
 
$ git status
# On branch master
nothing to commit (working directory clean)
 
如果本地做了改动但是没有提交,则
 
$ git status
# On branch master
# Changes not staged for commit:
# (use “git add …” to update what will be committed)
# (use “git checkout — …” to discard changes in working directory)
#
# modified: Orangebugs.java
#
no changes added to commit (use "git add" and/or "git commit -a")
 
另外,可以用下面的命令查看文件历史和以往的注释
 
$ git log Orangebugs.java
commit c919ced7f42f4bc06d563c1a1eaa107f2b2420d5
Author: GIT Admin  www.2cto.com  
Date: Sat Aug 13 22:54:57 2011 -0700
 
Added password strength meter functionality
 
commit c141b7bdbff429de35e36bafb2e43edc655e9957
Author: GIT Admin
Date: Sat Aug 13 20:08:02 2011 -0700
 
Initial upload of the project

7、可能碰见的错误:

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


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值