一些常用的Git命令(3)

11、mv 重命名
[root@linuxidc git]# ls
code1.py  code.py
[root@linuxidc git]# git mv code1.py code.txt        #重命名code1.py-->code.txt
[root@linuxidc git]# ls
code.py  code.txt
[root@linuxidc git]# git status                      #查看状态,显示 #  renamed:    code1.py -> code.txt
# On branch master
# Changes to be committed:
#  (use "git reset HEAD <file>..." to unstage)
#
#  renamed:    code1.py -> code.txt
#
[root@linuxidc git]# git add code.txt 
[root@linuxidc git]# git commit -m " Modify file name code1.py-->code.txt"
[master 924041d]  Modify file name code1.py-->code.txt
 1 files changed, 0 insertions(+), 0 deletions(-)
 rename code1.py => code.txt (100%)

12、rm 删除
[root@linuxidc git]# ll
total 8
-rw-r--r-- 1 root root 23 Oct  5 23:53 code.py
-rw-r--r-- 1 root root 23 Oct  5 23:32 code.txt
[root@linuxidc git]# git rm code.txt                    #删除code.txt
rm 'code.txt'
[root@linuxidc git]# ll
total 4
-rw-r--r-- 1 root root 23 Oct  5 23:53 code.py
[root@linuxidc git]# git commit -am " Delete file code.txt"
[master 82ec99e]  Delete file code.txt
 1 files changed, 0 insertions(+), 1 deletions(-)
 delete mode 100644 code.txt

13、show等价于rev-parse,只不过一个是简要一个是明细
[root@linuxidc git]# git show HEAD~                    #看hash值
commit 924041d5e2924e945f67816775869d4ceb9694dd
Author: sunshine <sunshine@git.com>
Date:  Wed Oct 5 23:57:25 2016 +0800
 
    Modify file name code1.py-->code.txt
 
diff --git a/code.txt b/code.txt
new file mode 100644
index 0000000..66708be
--- /dev/null
+++ b/code.txt
@@ -0,0 +1 @@
+print 'Sunshine Good!'
diff --git a/code1.py b/code1.py
deleted file mode 100644
index 66708be..0000000
--- a/code1.py
+++ /dev/null
@@ -1 +0,0 @@
-print 'Sunshine Good!'
[root@linuxidc git]# git rev-parse HEAD~                #仔细看hash值是一样的
924041d5e2924e945f67816775869d4ceb9694dd

14、cat-file 查看tree与parent
[root@linuxidc git]# git cat-file -t HEAD~            #-t 显示commit
commit
[root@linuxidc git]# git cat-file -p HEAD~            #-p 显示tree与parent
tree ea16f4c3781c4dc1f5e142eba114b0d5a1cefeaa
parent 865c84e5f13fb239f83e3e27bcf0f3a28990034e
author sunshine <sunshine@git.com> 1475683045 +0800
committer sunshine <sunshine@git.com> 1475683045 +0800
 
 Modify file name code1.py-->code.txt

15、reset 这个就比较复杂啦
[root@linuxidc git]# ll
total 4
-rw-r--r-- 1 root root 23 Oct  6 00:17 code.py
[root@linuxidc git]# git log --oneline                    #查看历史commit版本hash值82ec99e
82ec99e  Delete file code.txt
924041d  Modify file name code1.py-->code.txt
865c84e New add rom 'Sunshine Good~'
bf266f5 code1.py New add row Sunshine Good
7894d32 New add code1.py
b421347 New add code.py
[root@linuxidc git]# ll
total 4
-rw-r--r-- 1 root root 23 Oct  6 00:17 code.py
[root@linuxidc git]# git rm code.py                        #删除文件code.py
rm 'code.py'
[root@linuxidc git]# git commit -am "Delete file code.py"  #commit -am等价于执行 #git add filename # git commit -m "Delete fie code.py",提示删除成功
[master 3271a1d] Delete file code.py
 1 files changed, 0 insertions(+), 1 deletions(-)
 delete mode 100644 code.py
[root@linuxidc git]# ll                                    #查看不存在
total 0
[root@linuxidc git]# git status                            #也没报错
# On branch master
nothing to commit (working directory clean)
[root@linuxidc git]# git log --oneline                    #查看commit版本hash值
3271a1d Delete file code.py
82ec99e  Delete file code.txt
924041d  Modify file name code1.py-->code.txt
865c84e New add rom 'Sunshine Good~'
bf266f5 code1.py New add row Sunshine Good
7894d32 New add code1.py
b421347 New add code.py
[root@linuxidc git]# git reset --hard 82ec99e              #回滚到上个版本
HEAD is now at 82ec99e  Delete file code.txt
[root@linuxidc git]# ll                                    #OK文件回来了
total 4
-rw-r--r-- 1 root root 23 Oct  6 00:18 code.py
[root@linuxidc git]# git log --oneline                    #回滚成功
82ec99e  Delete file code.txt
924041d  Modify file name code1.py-->code.txt
865c84e New add rom 'Sunshine Good~'
bf266f5 code1.py New add row Sunshine Good
7894d32 New add code1.py
b421347 New add code.py

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

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