Git是目前世界上最先进的分布式版本控制系统
SVN是集中式的版本控制系统,而Git是分布式版本控制系统,集中式和分布式版本控制系统有什么区别呢?这个可以找度娘......
1.安装Git
yum install git
查看git版本
git --version
2.创建git本地用户名和邮箱.
git config --global user.name "Sanerii" git config --global user.email ylemail2002@sina.cn
查看git配置.
[root@localhost ~]# git config --list user.name=Sanerii user.email=ylemail2002@sina.cn
给git配置颜色.
git config --global color.ui true
3.创建版本库:
版本库又名仓库,英文名repository,你可以简单理解成一个目录,这个目录里面的所有文件都可以被Git管理起来,每个文件的修改、删除,Git都能跟踪,以便任何时刻都可以追踪历史,或者在将来某个时刻可以“还原”。
1.> 创建目录.
[root@localhost ~]# mkdir oldman [root@localhost ~]# cd oldman/ [root@localhost oldman]# ll total 0 [root@localhost oldman]#
2.>通过git init命令把这个目录变成Git可以管理的仓库:
[root@localhost oldman]# git init Initialized empty Git repository in /root/oldman/.git/ [root@localhost oldman]# ls -la total 12 drwxr-xr-x 3 root root 4096 Jan 23 13:59 . dr-xr-x---. 26 root root 4096 Jan 23 13:58 .. drwxr-xr-x 7 root root 4096 Jan 23 13:59 .git
#瞬间Git就把仓库建好了,而且告诉你是一个空的仓库(empty Git repository)
3.>编写文件提交到git,并运行git status命令看看结果:
添加文件到Git仓库,分两步:
第一步,使用命令git add <file>,将文件添加到暂存区,注意,可反复多次使用,添加多个文件;<文件需要存在或提前创建好.>
第二步,使用命令git commit,完成提交。
git add命令实际上就是把要提交的所有修改放到暂存区(Stage),然后,执行git commit就可以一次性把暂存区的所有修改提交到分支。
[root@localhost oldman]# echo "hello world" >> readme.txt #在git目录写一个文件 [root@localhost oldman]# git status # On branch master # # Initial commit # # Untracked files: # (use "git add <file>..." to include in what will be committed) # # readme.txt nothing added to commit but untracked files present (use "git add" to track) [root@localhost oldman]# [root@localhost oldman]# git add readme.txt #添加一个文件到git [root@localhost oldman]# git status #查看git状态 # On branch master # # Initial commit # # Changes to be committed: # (use "git rm --cached <file>..." to unstage) # # new file: readme.txt # [root@localhost oldman]# git commit -m "the first commit" #提交文件 [master (root-commit) 9fd15c4] the first commit files changed, 1 insertions(+), 0 deletions(-) create mode 100644 readme.txt [root@localhost oldman]# git status # On branch master nothing to commit (working directory clean) [root@localhost oldman]# echo "working..." >> readme.txt #向文件中追加内容 [root@localhost oldman]# git diff readme.txt #使用diff命令查看文件改变内容 diff --git a/readme.txt b/readme.txt index 3b18e51..5c1acd5 100644 --- a/readme.txt +++ b/readme.txt @@ -1 +1,2 @@ hello world +working... //为追加的内容 [root@localhost oldman]# git status # On branch master # Changed but not updated: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: readme.txt # no changes added to commit (use "git add" and/or "git commit -a") [root@localhost oldman]# git add readme.txt #添加文件到git [root@localhost oldman]# git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: readme.txt # [root@localhost oldman]# git commit -m "t2 commit" #提交文件 [master 4f34513] t2 commit 1 files changed, 1 insertions(+), 0 deletions(-) [root@localhost oldman]# git status # On branch master nothing to commit (working directory clean) [root@localhost oldman]#
小结
要随时掌握工作区的状态,使用git status命令。
如果git status告诉你有文件被修改过,用git diff可以查看修改内容。
原文:http://www.cnblogs.com/saneri/p/6341018.html