git常用命令及执行结果解释

大佬们都在使用命令行,作为菜鸟怎么能落后呢。但是英语又是在菜地抠脚,怎么办?一条条翻译呗。

一、git status

$ git status    //git status命令查看仓库的当前状态。以下是执行该命令后出现的结果之一。

//在git add之前使用该命令,会出现以下结果
On branch master    //显示当前所在分支(例如:此处显示当前分支为mater主分支)
Changes not staged for commit:    //在进行commit之前,有部分改变还没有加入暂存区,可以利用以下命令进行操作
  (use "git add ..." to update what will be committed)    //git add 文件名---将该文件先添加到暂存区
  (use "git checkout -- ..." to discard changes in working directory)    //git checkout --文件名---将文件移除

    modified:   readme.txt    //标明发生改变的文件名(或者文件列表)

no changes added to commit (use "git add" and/or "git commit -a")




//在git add之前使用该命令,如果有新文件添加到工作区,则会出现以下结果
On branch master
Changes not staged for commit:
  (use "git add ..." to update what will be committed)
  (use "git checkout -- ..." to discard changes in working directory)

    modified:   readme.txt

Untracked files:    //从未添加过的文件列表(新增加的)
  (use "git add ..." to include in what will be committed)    //可以通过git add 该文件夹名 -----将文件添加到暂存区

    LICENSE

no changes added to commit (use "git add" and/or "git commit -a")





//在使用git add之后,使用该命令,会出现以下结果
On branch master    //显示当前所在分支(例如:此处显示当前分支为mater主分支)
Changes to be committed:    //已经做好commit准备
  (use "git reset HEAD ..." to unstage)    //可以通过git reset HEAD 文件名---将该文件移出堆栈

    modified:   readme.txt    //标明发生改变的文件名(或者文件列表)




//执行git commit后,使用该命令,会出现以下结果
On branch master    //显示当前所在分支(例如:此处显示当前分支为mater主分支)
nothing to commit, working tree clean    //没有任何需要commit的,工作目录已经清空

二、git diff

$ git diff readme.txt    //git diff 文件名---查看该文件修改了什么内容(以下结果暂时不太懂,稍后注释)

diff --git a/readme.txt b/readme.txt
index 46d49bf..9247db6 100644
--- a/readme.txt
+++ b/readme.txt
@@ -1,2 +1,2 @@
-Git is a version control system.
+Git is a distributed version control system.
 Git is free software.

三、git commit

$ git commit -m "add distributed"    //git commit -m "本次提交的描述信息",以下是执行命令后的可能结果

[master e475afc] add distributed    //[master(当前所在分支) 版本号] 本次提交的描述信息
 1 file changed, 1 insertion(+), 1 deletion(-)    //1个文件改变,1行增加,1行删除

四、git log

$ git log    //git log 查看从最近到最远的提交日志

commit 1094adb7b9b3807259d8cb349e7df1d4d6477073 (HEAD -> master)    //commit提交的版本号 (HEAD -> 当前所在分支)
Author: Michael Liao     //该commit的作者
Date:   Fri May 18 21:06:15 2018 +0800    //该commit提交的时间

    append GPL        //该commit的描述

commit e475afc93c209a690c39c13a46716e8fa000c366
Author: Michael Liao 
Date:   Fri May 18 21:03:36 2018 +0800

    add distributed

commit eaadf4e385e865d25c48e7ca9c8395c3f7dfaef0
Author: Michael Liao 
Date:   Fri May 18 20:59:18 2018 +0800

    wrote a readme file

如果觉得上面打印的日志内容太多,可以加上--pretty=oneline

$ git log --pretty=oneline    //查看日志仅一行显示

1094adb7b9b3807259d8cb349e7df1d4d6477073 (HEAD -> master) append GPL    //版本号 (HEAD -> 当前所在分支) 该commit的描述
e475afc93c209a690c39c13a46716e8fa000c366 add distributed
eaadf4e385e865d25c48e7ca9c8395c3f7dfaef0 wrote a readme file

五、git reset

先通过git log找到自己需要回退的版本

//如果回退到距离最近比较近的版本,可以使用以下命令:
$ git reset --hard HEAD~1    //git reset --hard HEAD~回退数(从当前版本回退到上一个版本,则为1,回退上上个版本,则为2,以此类推)

HEAD is now at e475afc add distributed    //(回退成功) 当前所在版本号为 e475afc  该版本的commit描述
//如果回退的版本比较远,可以使用版本号进行回退操作:
$ git reset --hard 1094a    //git reset --hard 需要回退到的版本号

HEAD is now at 83b0afe append GPL    //(回退成功) 当前所在版本号为 83b0afe  该版本的commit描述

六、git reflog

如果回退了版本后,又后悔了,想要重新返回之前的版本怎么办?这个时候就要用到reflog,找到需要回退的版本号,然后执行上面的git reset操作就可以啦

$ git reflog    //git reflog查看命令操作历史

e475afc HEAD@{1}: reset: moving to HEAD^
1094adb (HEAD -> master) HEAD@{2}: commit: append GPL
e475afc HEAD@{3}: commit: add distributed
eaadf4e HEAD@{4}: commit (initial): wrote a readme file

你可能感兴趣的:(git常用命令及执行结果解释)