git其实是一种多人开发项目时候的版本控制系统,是由LINUX之父Linus开发的,与SVN最大的区别在于可以支持离线操作。
然后yum install git -y
[iyunv@localhost ~]#git --version 查看git版本
[iyunv@localhost ~]#git config --global user.name dangwanqiang 当前用户姓名和邮箱
[iyunv@localhost ~]#git config --global color.ui true 在git输出中开启颜色显示
[iyunv@localhost ~]#git config --list
1
2
3
| user.name=dangwanqiang
user.email=goodang517@163.com
color.ui=true
|
实际也是写入文件中去
[iyunv@localhost ~]#cat ~/.gitconfig
[iyunv@localhost ~]#git init github
[iyunv@localhost ~]#cd github
[iyunv@localhost github]#ls -A
.git 可以看到隐藏的目录.git(Git版本库,repository)
三部曲:1.init 2.add 3.commit
[iyunv@localhost github]# touch READ.txt a.py //创建自己的工作文件
[iyunv@localhost github]# git status
1
2
3
4
5
6
7
8
9
10
| # 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)
|
[iyunv@localhost github]# git add a.py //将a.py加到版本库
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| [iyunv@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
|
[iyunv@localhost github]# git add READ.txt //将READ.txt加到版本库
[iyunv@localhost github]# git status
1
2
3
4
5
6
7
8
9
10
| # On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached <file>..." to unstage)
#
#new file: READ.txt
#new file: a.py
#
|
[iyunv@localhost github]# git commit -m 'init commit' //-m参数指定提交说明
1
2
3
4
| [master (root-commit) 9f045e6] init commit
2 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 READ.txt
create mode 100644 a.py
|
[iyunv@localhost github]# git status
1
2
| # On branch master
nothing to commit, working directory clean
|
[iyunv@localhost github]# vi a.py //对a.py再次进行修改
[iyunv@localhost github]# git status -s M a.py 注:工作区与暂缓区不同,即M标志位在第二位,也意味着需要执行add [iyunv@localhost github]# git status
1
2
3
4
5
6
7
8
| # 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")
|
[iyunv@localhost github]# git diff //查看工作区与暂缓区具体不同 1
2
3
4
5
6
7
| diff --git a/a.py b/a.py
index 72943a1..dbee026 100644
--- a/a.py
+++ b/a.py
@@ -1 +1,2 @@
aaa
+bbb
|
[iyunv@localhost github]# git add a.py
[iyunv@localhost github]# git status -s
M a.py
注:暂缓区与最终版本库不同,即M标志位在第一位,也意味着需要执行commit
[iyunv@localhost github]# git status
1
2
3
4
5
6
| # On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
#modified: a.py
#
|
[iyunv@localhost github]# git diff --staged //查看暂缓区与最终版本库的具体不同 1
2
3
4
5
6
7
| diff --git a/a.py b/a.py
index 72943a1..dbee026 100644
--- a/a.py
+++ b/a.py
@@ -1 +1,2 @@
aaa
+bbb
|
[iyunv@localhost github]# git rm a.py //删除缓存区和工作区的文件
[iyunv@localhost github]# git status
1
2
3
4
5
6
| # On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
#deleted: a.py
#
|
[iyunv@localhost github]# git status -s
[iyunv@localhost github]# ls
READ.txt
[iyunv@localhost github]# git commit -m 'delete a.py' //将删除提交到最终版本库
1
2
3
| [master 480eda1] delete a.py
1 file changed, 2 deletions(-)
delete mode 100644 a.py
|
[iyunv@localhost github]# git status
1
2
| # On branch master
nothing to commit, working directory clean
|
[iyunv@localhost github]# git rm --cached READ.txt //只删除暂存区的文件
[iyunv@localhost github]# ls
READ.txt
[iyunv@localhost github]# git reset READ.txt //从最终版本库恢复文件到暂存区
[iyunv@localhost github]# ls
READ.txt
[iyunv@localhost github]# git status
[iyunv@localhost github]# git mv READ.txt READ.LL
[iyunv@localhost github]# git commit -m 'rename read.txt'
|