如何将git文件还原到其临时区域版本?

Geo*_*Geo 69 git

假设我有一个名为的文件a.txt.我将它添加到临时区域,然后我修改它.我怎么能把它恢复到我添加它的时候呢?

aby*_*byx 65

git checkout a.txt

如果你输入,Git会告诉你git status:

# 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
#
Run Code Online (Sandbox Code Playgroud)

  • @Daenyth我在发布之前已经检查过了,你可以看到输出显示了在不同状态下重置文件的不同方法(分阶段与非分阶段) (3认同)

non*_*lar 25

git checkout -- a.txt

这个页面上的另一个答案没有--,并导致一些混乱.

这是Git在您输入时告诉您的内容git status:

# 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
#
Run Code Online (Sandbox Code Playgroud)

  • 您最好告诉我们区别,而不是发布以前引用的内容。 (2认同)