23121321 发表于 2016-4-28 09:42:49

linux命令之git

git其实是一种多人开发项目时候的版本控制系统,是由LINUX之父Linus开发的,与SVN最大的区别在于可以支持离线操作。
   首先安装:我用的网易的yum源http://mirrors.163.com/centos/6/os/x86_64/            然后yum install git -y




[*]Git初始化



#git --version                              查看git版本
#git config --global user.name dangwanqiang   当前用户姓名和邮箱
#git config --global color.ui true            在git输出中开启颜色显示
#git config --list

1
2
3
user.name=dangwanqiang
user.email=goodang517@163.com
color.ui=true




实际也是写入文件中去

#cat ~/.gitconfig

1
2
3
4
5

name = dangwanqiang
email = goodang517@163.com

ui = true






[*]建立一个工作目录


#git init github
#cd github
#ls -A                               
.git                  可以看到隐藏的目录.git(Git版本库,repository)


[*]在工作目录下的建立操作


三部曲:1.init2.add3.commit

# touch READ.txta.py         //创建自己的工作文件
# 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)




# git add a.py                    //将a.py加到版本库

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 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




# git add READ.txt            //将READ.txt加到版本库
# 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
#




# git commit -m 'init commit'         //-m参数指定提交说明

1
2
3
4
init commit
2 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 READ.txt
create mode 100644 a.py




# git status

1
2
# On branch master
nothing to commit, working directory clean




# vi a.py                            //对a.py再次进行修改

# git status -s                      M a.py            注:工作区与暂缓区不同,即M标志位在第二位,也意味着需要执行add# 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")




# 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




# git add a.py

# git status -s                  
Ma.py
         注:暂缓区与最终版本库不同,即M标志位在第一位,也意味着需要执行commit

# 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
#




# 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





[*]在工作目录下的撤销误操作





[*]在工作目录下的删除重命名操作

# git rm a.py                //删除缓存区和工作区的文件

1
rm 'a.py'




# 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
#




# git status -s

1
Da.py




# ls
READ.txt

# git commit -m 'delete a.py'   //将删除提交到最终版本库

1
2
3
delete a.py
1 file changed, 2 deletions(-)
delete mode 100644 a.py




# git status

1
2
# On branch master
nothing to commit, working directory clean




# git rm --cached READ.txt       //只删除暂存区的文件

1
rm 'READ.txt'




# ls
READ.txt
# git reset READ.txt             //从最终版本库恢复文件到暂存区
# ls
READ.txt
# git status

1
# On branch master




# git mv READ.txt READ.LL
# git commit -m 'rename read.txt'

页: [1]
查看完整版本: linux命令之git