git其实是一种多人开发项目时候的版本控制系统,是由LINUX之父Linus开发的,与SVN最大的区别在于可以支持离线操作。
首先安装:我用的网易的yum源http://mirrors.163.com/centos/6/os/x86_64/
然后yum install git -y
Git初始化
[root@localhost ~]#git --version 查看git版本
[root@localhost ~]#git config --global user.name dangwanqiang 当前用户姓名和邮箱
[root@localhost ~]#git config --global color.ui true 在git输出中开启颜色显示
[root@localhost ~]#git config --list
user.name=dangwanqiang user.email=goodang517@163.com color.ui=true
实际也是写入文件中去
[root@localhost ~]#cat ~/.gitconfig
[user] name = dangwanqiang email = goodang517@163.com [color] ui = true
建立一个工作目录
[root@localhost ~]#git init github
[root@localhost ~]#cd github
[root@localhost github]#ls -A
.git 可以看到隐藏的目录.git(Git版本库,repository)
在工作目录下的建立操作
三部曲:1.init 2.add 3.commit
[root@localhost github]# touch READ.txt a.py //创建自己的工作文件
[root@localhost github]# git status
# On branch master # # Initial commit # # Untracked files: //未添加到版本库的文件 # (use "git add <file>..." to include in what will be committed) # #READ.txt #a.py nothing added to commit but untracked files present (use "git add" to track)
[root@localhost github]# git add a.py //将a.py加到版本库
[root@localhost github]# git status # On branch master # # Initial commit # # Changes to be committed: # (use "git rm --cached <file>..." to unstage) # #new file: a.py # # Untracked files: # (use "git add <file>..." to include in what will be committed) # #READ.txt
[root@localhost github]# git add READ.txt //将READ.txt加到版本库
[root@localhost github]# git status
# On branch master # # Initial commit # # Changes to be committed: # (use "git rm --cached <file>..." to unstage) # #new file: READ.txt #new file: a.py #
[root@localhost github]# git commit -m ‘init commit‘ //-m参数指定提交说明
[master (root-commit) 9f045e6] init commit 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 READ.txt create mode 100644 a.py
[root@localhost github]# git status
# On branch master nothing to commit, working directory clean
[root@localhost github]# vi a.py //对a.py再次进行修改
[root@localhost github]# git status -s
M a.py
注:工作区与暂缓区不同,即M标志位在第二位,也意味着需要执行add
[root@localhost github]# git status
# On branch master # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory # #modified: a.py # no changes added to commit (use "git add" and/or "git commit -a")
[root@localhost github]# git diff //查看工作区与暂缓区具体不同
diff --git a/a.py b/a.py index 72943a1..dbee026 100644 --- a/a.py +++ b/a.py @@ -1 +1,2 @@ aaa +bbb
[root@localhost github]# git add a.py
[root@localhost github]# git status -s
M a.py
注:暂缓区与最终版本库不同,即M标志位在第一位,也意味着需要执行commit
[root@localhost github]# git status
# On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # #modified: a.py #
[root@localhost github]# git diff --staged //查看暂缓区与最终版本库的具体不同
diff --git a/a.py b/a.py index 72943a1..dbee026 100644 --- a/a.py +++ b/a.py @@ -1 +1,2 @@ aaa +bbb
在工作目录下的撤销误操作
在工作目录下的删除重命名操作
[root@localhost github]# git rm a.py //删除缓存区和工作区的文件
rm ‘a.py‘
[root@localhost github]# git status
# On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # #deleted: a.py #
[root@localhost github]# git status -s
D a.py
[root@localhost github]# ls
READ.txt
[root@localhost github]# git commit -m ‘delete a.py‘ //将删除提交到最终版本库
[master 480eda1] delete a.py 1 file changed, 2 deletions(-) delete mode 100644 a.py
[root@localhost github]# git status
# On branch master nothing to commit, working directory clean
[root@localhost github]# git rm --cached READ.txt //只删除暂存区的文件
rm ‘READ.txt‘
[root@localhost github]# ls
READ.txt
[root@localhost github]# git reset READ.txt //从最终版本库恢复文件到暂存区
[root@localhost github]# ls
READ.txt
[root@localhost github]# git status
# On branch master
[root@localhost github]# git mv READ.txt READ.LL
[root@localhost github]# git commit -m ‘rename read.txt‘
本文出自 “up for future....” 博客,请务必保留此出处http://goodang.blog.51cto.com/10277564/1768349
原文地址:http://goodang.blog.51cto.com/10277564/1768349