一些常用的Git命令(2)

6、checkout 切换 创建分支
[root@linuxidc git]# git checkout -b dev
Switched to a new branch 'dev'
[root@linuxidc git]# git branch
* dev
  master
[root@linuxidc git]# git checkout master
Switched to branch 'master'
[root@linuxidc git]# git branch
  dev
* master

7、clone 克隆一个repository 信息在本地目录,哪自己之前做好的gitolite
[root@Redis_master ~]# git clone git@127.0.0.1:dev
Initialized empty Git repository in /root/dev/.git/
remote: Counting objects: 9, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 9 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (9/9), done.
[root@redis_master ~]# ls
anaconda-ks.cfg  appendonly.aof  dev  id_rsa.pub  install.log  install.log.syslog
[root@redis_master ~]# cd dev/
[root@redis_master dev]# ls
test.txt

8、diff 对比文件
[root@linuxidc git]# ls
code1.py  code.py
[root@linuxidc git]# git status 
# On branch master
nothing to commit (working directory clean)
[root@linuxidc git]# vim code1.py 
[root@linuxidc git]# git diff                    #这里是对比暂存区与工作区对比
diff --git a/code1.py b/code1.py
index e69de29..66708be 100644
--- a/code1.py
+++ b/code1.py
@@ -0,0 +1 @@
+print 'Sunshine Good!'
[root@linuxidc git]# git diff --staged            #这里是暂存区对比staged也就是我们commit的staged区
[root@linuxidc git]# git add code1.py            #添加到暂存区
[root@linuxidc git]# git diff                    #工作区对比暂存区
[root@linuxidc git]# git diff --staged            #暂存区对比commit的staged
diff --git a/code1.py b/code1.py
index e69de29..66708be 100644
--- a/code1.py
+++ b/code1.py
@@ -0,0 +1 @@
+print 'Sunshine Good!'
[root@linuxidc git]# git commit -m "code1.py New add row Sunshine Good"    #提交
[master bf266f5] code1.py New add row Sunshine Good
 1 files changed, 1 insertions(+), 0 deletions(-)
[root@linuxidc git]# git diff --staged                                    #对比暂存区以staged区
[root@linuxidc git]# git diff                                              #对比工作区对比暂存区

9、log 就是日志咯,不过这里显示的可能比较诡异
[root@linuxidc git]# git log                                #详细显示
commit bf266f5673089439efdd632a38b7220390af5cc7
Author: sunshine <sunshine@git.com>
Date:  Wed Oct 5 23:34:03 2016 +0800
 
    code1.py New add row Sunshine Good
 
commit 7894d320ac92997fdb4d0c74487d87def3ebf756
Author: root <root@linuxidc.(none)>
Date:  Wed Oct 5 23:20:29 2016 +0800
 
    New add code1.py
 
commit b4213472064fbc292eff843b6a67549344197495
Author: root <root@linuxidc.(none)>
Date:  Wed Oct 5 21:45:23 2016 +0800
 
    New add code.py
[root@linuxidc git]# git log --oneline                      #简要显示
bf266f5 code1.py New add row Sunshine Good
7894d32 New add code1.py
b421347 New add code.py
[root@linuxidc git]# git log --color --graph                #显示版本分支示意图       
* commit bf266f5673089439efdd632a38b7220390af5cc7
| Author: sunshine <sunshine@git.com>
| Date:  Wed Oct 5 23:34:03 2016 +0800

|    code1.py New add row Sunshine Good

* commit 7894d320ac92997fdb4d0c74487d87def3ebf756
| Author: root <root@linuxidc.(none)>
| Date:  Wed Oct 5 23:20:29 2016 +0800

|    New add code1.py

* commit b4213472064fbc292eff843b6a67549344197495
  Author: root <root@linuxidc.(none)>
  Date:  Wed Oct 5 21:45:23 2016 +0800
   
      New add code.py

10、merge 合并分支
[root@linuxidc git]# ls
code1.py  code.py
[root@linuxidc git]# git checkout -b dev        #创建并切换至分支dev
Switched to a new branch 'dev'
[root@linuxidc git]# git branch                #查看当前位置所在分支
* dev
  master
[root@linuxidc git]# vim code.py 
[root@linuxidc git]# cat code.py 
print 'Sunsine !'
[root@linuxidc git]# git checkout master        #切换回master
M  code.py
Switched to branch 'master'
[root@linuxidc git]# git merge dev              #合并分支dev
Already up-to-date.
[root@linuxidc git]# cat code.py 
print 'Sunsine !'
[root@linuxidc git]# git branch -d dev          #删除分支
Deleted branch dev (was bf266f5)

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/13654.html