• GIT入门笔记(11)- 多种撤销修改场景和对策--实战练习


    1、检查发现目前没有变化
    $ git status
    On branch master
    nothing to commit, working tree clean

    $ cat lsq.txt
    2222

    2、修改文件并add

    $ echo "3333" > lsq.txt
    $ git add lsq.txt
    warning: LF will be replaced by CRLF in lsq.txt.
    The file will have its original line endings in your working directory.

    3、接着修改
    $ echo "4444" > lsq.txt
    $ cat lsq.txt
    4444

    4、用checkout撤销add后的修改
    $ git checkout -- lsq.txt

    $ cat lsq.txt
    3333

    5、用reset恢复stage区到Head,然后checkout到工作区

    $ git reset HEAD lsq.txt
    Unstaged changes after reset:
    M lsq.txt

    $ cat lsq.txt
    3333

    $ git checkout -- lsq.txt

    $ cat lsq.txt
    2222

    6、检查历史版本号
    $ git reflog lsq.txt
    9ff99f2 HEAD@{0}: commit: 2222
    9104638 HEAD@{1}: commit: 11111

    7、回退到commit的历史版本
    $ git reset --hard 9104638
    HEAD is now at 9104638 11111

    $ cat lsq.txt
    1111111

  • 相关阅读:
    ubuntu 1804 docker install
    windows shortcut
    gallary
    g++ play
    linux profile
    terminator
    tmux
    ubuntu18
    windows toolkit
    windows terminal CLI
  • 原文地址:https://www.cnblogs.com/lexiaofei/p/6535533.html
Copyright © 2020-2023  润新知