• 关于[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

  • 相关阅读:
    PCL点云库——关键点
    ES6 入门教程 10 对象的扩展 10.4 属性的可枚举性和遍历 & 10.5 super 关键字
    leetcode53 -- 最大数组和
    「SpringBoot」07 指标监控
    Moment.js的常用函数、借助vue和Moment.js实现一个简单的时钟
    大爷,快来玩呀!带禁手规则的五子棋实践强化学习理论
    揭秘AD域:探讨在企业网络管理的优势与劣势
    Laravel 博客开发|后台项目管理
    Nginx proxy_set_header参数设置
    软件测试女生可以学习么?现在还能入行么?
  • 原文地址:https://blog.csdn.net/qq_53318060/article/details/127760045