• 关于[git reset]


    git reset

    git reset < mode > < commit >

    Set the current branch head (HEAD) to ,optionally modifying index and working tree to match.

    This form resets the current branch head to and possibly updates the index (resetting it to the tree of ) and the working tree depending on . If is omitted,defaults to --mixed.

    Step 1: Move HEAD
    The first thing reset will do is move what HEAD points to.
    This means if HEAD is set to the master branch, running git reset 9e5e6a4 will start by making master point to 9e5e6a4.
    # HEAD依然指向master,但是改变master指向,master指向的不再是最新的commit
    
    Step 2: Updating the Index (--mixed)
    The next thing reset will do is to update the index with the contents of whatever snapshot HEAD now points to.
    
    Step 3: Updating the Working Directory (--hard)
    The third thing that reset will do is to make the working directory look like the index.
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    在这里插入图片描述

    # Does not touch the index file or the working tree at all, but resets the head to 
    # 相当于取消了上一次的commit,可以使用这条指令(当发现上一次的提交需要进行修改时)
    git reset --soft# 仅移动HEAD指向分支的指向(即只移动master)
    
    • 1
    • 2
    • 3

    在这里插入图片描述

    # Resets the index but not the working tree, This is the default action.
    git reset --mixed# 移动HEAD分支指向, 用HEAD分支指向的当前快照的内容来更新索引
    
    • 1
    • 2

    在这里插入图片描述

    # Resets the index and working tree.
    # Any changes to tracked files in the working tree since  are discarded.
    git reset --hard# 移动HEAD指向, 用HEAD分支指向的当前快照的内容来更新索引, 更新工作目录
    
    • 1
    • 2
    • 3

    Reset With a Path

    # 指定path,reset会跳过第一步,将剩余的操作限定到特定的文件或文件集.
    If you specify a path,reset will skip step 1,and limit the remainder of its actions to a specific file or set of files.
    # HEAD不能移动,但是index和工作区可以部分更新
    HEAD is just a pointer, and you can’t point to part of one commit and part of another.
    But the index and working directory can be partially updated, so reset proceeds with steps 2 and 3.
    
    # 这三个一样
    git reset file.txt
    git reset HEAD file.txt
    git reset --mixed HEAD file.txt
    
    which will:
    1.Move the branch HEAD points to (skipped).(跳过step1,不移动HEAD指向)
    2.Make the index look like HEAD (stop here).(用HEAD指向的内容填充index)
    it essentially just copies file.txt from HEAD to the index.
    
    这实际上是取消暂存的效果
    在HEAD之后,我们进行了文件修改,并且git add,还没commit
    此时git reset该文件(用HEAD的内容填充index),就是取消上一步的git add
    
    # 不从HEAD中提取,而是从eb43bf中提取
    git reset eb43bf file.txt
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    Git version 2.23.0 introduced a new command: git restore.
    From Git version 2.23.0 onwards, Git will use git restore instead of git reset for many undo operations.
    # 等价于前面的 git reset 
    git restore --staged <file>
    
    • 1
    • 2
    • 3
    • 4

    git reset 三种模式
    撤销Git已经push的操作
    git删除push到远程服务器的commit
    git reset 文档
    gitReset

  • 相关阅读:
    Mysql——查询sql语句练习
    nordic——long range测试
    c语言以及高级语言中的float到底是什么以及IEEE754
    【C++】详解 void*
    低成本、低门槛、易部署,4800+万户中小企业数字化转型新选择
    Kotlin高仿微信-第22篇-个人信息-修改昵称
    阿里二面:Java 序列化和反序列化为什么要实现 Serializable 接口?
    javaEE基于springboot民宿推荐系统springmvc+mybatis+jsp]
    Android——gradle插件配置方式——dependencies和plugins
    骨传导耳机用久了伤耳朵吗?骨传导耳机有什么优势
  • 原文地址:https://blog.csdn.net/qq_53318060/article/details/127760045