• Git-第二篇廖雪峰Git教程学习笔记(1)基本命令,版本回退


    1、安装Git-2.16.2-64-bit.exe后,设置用户名,用户邮箱

    #--global参数,表示你这台机器上所有的Git仓库都会使用这个配置,当然也可以对某个仓库指定不同的用户名和Email地址。
    $ git config --global user.name "Your Name" $ git config --global user.email "email@example.com"

    2、创建版本库

      命令:git init

      版本库:版本库又名仓库,英文名repository,你可以简单理解成一个目录,这个目录里面的所有文件都可以被Git管理起来,每个文件的修改、删除,Git都能跟踪,以便任何时刻都可以追踪历史,或者在将来某个时刻可以“还原”。

    3、把文件添加到版本库

      命令:git add 文件

      解析:将文件添加到暂存区

      命令:git commit -m "log description"

      解析:将文件添加到本地库。-m命令用于添加提交说明日志。

       命令:git status

       解析:查看当前的文件修改状态。上面截图因为我们已经提交到本地仓库了,所以当前库中没有任何修改。

      命令:git diff 文件

      解析:查看指定文件差异。

    lfy@lfy-PC MINGW64 /c/fyliu/lfyTemp/gitLocalRepository/yangjie (master)
    $ git status
    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:   readme.txt
    
    no changes added to commit (use "git add" and/or "git commit -a")
    
    lfy@lfy-PC MINGW64 /c/fyliu/lfyTemp/gitLocalRepository/yangjie (master)
    $ git diff readme.txt
    warning: LF will be replaced by CRLF in readme.txt.
    The file will have its original line endings in your working directory.
    diff --git a/readme.txt b/readme.txt
    index 9c69c9c..4b1c78e 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.
    
    lfy@lfy-PC MINGW64 /c/fyliu/lfyTemp/gitLocalRepository/yangjie (master)
    $

    4、版本回退

       命令:git log [--pretty=oneline]

       解析:显示从最近到最远的提交日志

    lfy@lfy-PC MINGW64 /c/fyliu/lfyTemp/gitLocalRepository/yangjie (master)
    $ git log
    commit adde96d057448c792343465df3aee108764defbd (HEAD -> master)
    Author: lfy <1220429263@qq.com>
    Date:   Sat Aug 24 21:08:03 2019 +0800
    
        add GPL
    
    commit 31728b8d6ec5a40ed7eca72aca63533d8625b423
    Author: lfy <1220429263@qq.com>
    Date:   Sat Aug 24 20:47:26 2019 +0800
    
        add distributed
    
    commit 586474b5bd16e377df3b657ffc1b35f663a69038
    Author: lfy <1220429263@qq.com>
    Date:   Sat Aug 24 20:33:10 2019 +0800
    
        create readme.txt

       在Git中,用HEAD表示当前版本,上一个版本就是HEAD^,上上一个版本就是HEAD^^,当然往上100个版本写100个^比较容易数不过来,所以写成HEAD~100。

      现在,我们要把当前版本append GPL回退到上一个版本add distributed,就可以使用git reset命令

       命令:git reset --hard commit_id

       解析:

    lfy@lfy-PC MINGW64 /c/fyliu/lfyTemp/gitLocalRepository/yangjie (master)
    $ git reset --hard HEAD^
    HEAD is now at 31728b8 add distributed

        再次查看log,发现我们最后一次提交的内容已经找不到了。但是,只要当前窗口没有关闭(或者关闭了但你要记得commit id),还是可以再找回的,要输入之前查看的commit id。(即adde96d057...)

    lfy@lfy-PC MINGW64 /c/fyliu/lfyTemp/gitLocalRepository/yangjie (master)
    $ git log
    commit 31728b8d6ec5a40ed7eca72aca63533d8625b423 (HEAD -> master)
    Author: lfy <1220429263@qq.com>
    Date:   Sat Aug 24 20:47:26 2019 +0800
    
        add distributed
    
    commit 586474b5bd16e377df3b657ffc1b35f663a69038
    Author: lfy <1220429263@qq.com>
    Date:   Sat Aug 24 20:33:10 2019 +0800
    
        create readme.txt
    
    lfy@lfy-PC MINGW64 /c/fyliu/lfyTemp/gitLocalRepository/yangjie (master)
    $ git reset --hard adde96
    HEAD is now at adde96d add GPL
    
    lfy@lfy-PC MINGW64 /c/fyliu/lfyTemp/gitLocalRepository/yangjie (master)
    $ cat readme.txt
    GIt is a distributed version control system.
    Git is free software distributed under the GPL.
    
    lfy@lfy-PC MINGW64 /c/fyliu/lfyTemp/gitLocalRepository/yangjie (master)
    $ git log
    commit adde96d057448c792343465df3aee108764defbd (HEAD -> master)
    Author: lfy <1220429263@qq.com>
    Date:   Sat Aug 24 21:08:03 2019 +0800
    
        add GPL
    
    commit 31728b8d6ec5a40ed7eca72aca63533d8625b423
    Author: lfy <1220429263@qq.com>
    Date:   Sat Aug 24 20:47:26 2019 +0800
    
        add distributed
    
    commit 586474b5bd16e377df3b657ffc1b35f663a69038
    Author: lfy <1220429263@qq.com>
    Date:   Sat Aug 24 20:33:10 2019 +0800
    
        create readme.txt
    
    lfy@lfy-PC MINGW64 /c/fyliu/lfyTemp/gitLocalRepository/yangjie (master)
    $

       命令:git reflog

       解析:记录你的命令

    lfy@lfy-PC MINGW64 /c/fyliu/lfyTemp/gitLocalRepository/yangjie (master)
    $ git reflog
    adde96d (HEAD -> master) HEAD@{0}: reset: moving to adde96
    31728b8 HEAD@{1}: reset: moving to HEAD^
    adde96d (HEAD -> master) HEAD@{2}: commit: add GPL
    31728b8 HEAD@{3}: commit: add distributed
    586474b HEAD@{4}: commit (initial): create readme.txt
    
    lfy@lfy-PC MINGW64 /c/fyliu/lfyTemp/gitLocalRepository/yangjie (master)
    $
  • 相关阅读:
    jsp session练习简单的登录
    JSP练习:编写登录程序,错误时跳转
    1.JSON抓取文件解析文件
    java ee 在数据库中执行增删改查
    java ee cookie方法键值对输出
    java ee cookie方法包括在cookie输出的中文转换
    java编写在数据库中按条件查询数据
    java 在数据库中添加新信息
    java ee 输出三角形
    java ee 五的阶乘
  • 原文地址:https://www.cnblogs.com/ZeroMZ/p/11405816.html
Copyright © 2020-2023  润新知