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

1、下载和安装GIT

#下载
wget http://kernel.org/pub/software/scm/git/git-1.7.6.tar.bz2
#解压
tar xvfj git-1.7.6.tar.bz2
#编译安装
cd git-1.7.6
./configure
make
make install

2、初始化配置

#验证是否安装好
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
#查看配置文件
cat ~/.gitconfig

[user]
name = GIT Admin
email = obugs.net@gmail.com

3、建立工程

#定义git工程
cd /home/obugs/projects/orangebugs
git init
Initialized empty Git repository in /home/obugs/projects/orangebugs/.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、向工程添加和提交文件

#添加文件
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 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 #提交文件 git add Orangebugs.java git commit
[master 80f10a9] Added password strength meter functionality
1 files changed, 56 insertions(+), 7 deletions(-)

6、查看状态和查看注释

#查看状态(无改动)
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

 

posted @ 2015-08-31 14:01  boystar  阅读(275)  评论(0编辑  收藏  举报