如何将git文件还原为暂存区版本? [英] How do you revert a git file to its staging area version?

查看:112
本文介绍了如何将git文件还原为暂存区版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个名为 a.txt 的文件.我将其添加到暂存区域,然后对其进行修改.如何将其恢复为添加时的状态?

Let's say I have a file named a.txt. I add it to the staging area, and then I modify it. How could I return it to the way it was when I added it?

推荐答案

  • Git 2.23之前: git checkout a.txt
  • 从Git 2.23开始: git restore a.txt
  • 如果您键入 git status ,Git会告诉您.

    Git tells you this if you type git status.

    Git 2.23之前的版本:

    Prior to Git 2.23:

    # On branch master
    # Changes to be committed:
    #   (use "git reset HEAD <file>..." to unstage)
    #
    # modified:   a
    #
    # Changed but not updated:
    #   (use "git add <file>..." to update what will be committed)
    #   (use "git checkout -- <file>..." to discard changes in working directory)
    #
    # modified:   a
    #
    

    从Git 2.23开始:

    Starting from Git 2.23:

    On branch master
    Changes to be committed:
      (use "git restore --staged <file>..." to unstage)
            modified:   a
    
    Changes not staged for commit:
      (use "git add <file>..." to update what will be committed)
      (use "git restore <file>..." to discard changes in working directory)
            modified:   a
    

    这篇关于如何将git文件还原为暂存区版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆