【问题标题】:how to get a file from the staging area?如何从暂存区获取文件?
【发布时间】:2015-06-05 19:43:02
【问题描述】:

我有一个文件“a.txt”

git add a.txt

现在,我删除 a.txt(或修改它)。

那我想要那个我已经添加到暂存区的.txt

我该怎么做?

【问题讨论】:

    标签: git staging


    【解决方案1】:

    git status 的输出包含您要查找的信息:

    # Changes not staged for commit:
    #   (use "git add <file>..." to update what will be committed)
    #   (use "git checkout -- <file>..." to discard changes in working directory)
    

    因此,在这种情况下,您应该运行:

    git checkout -- a.txt
    

    【讨论】:

    • 这真的很管用。
    • 所以git checkout -- a.txt 从暂存区获取它,git checkout HEAD a.txt 从存储库获取它
    • @user3571278 更正确,它从 HEAD 指针下的提交中获取。您可以提供任何其他绝对或相对指针,例如分支或标记名称、提交 sha1、stash、reflog 和 ^~ 修饰符。哦,还有遥控器。
    猜你喜欢
    • 2013-11-12
    • 2021-06-20
    • 1970-01-01
    • 2020-11-14
    • 2022-12-04
    • 2023-03-17
    • 2021-04-17
    • 2012-09-25
    • 2021-03-12
    相关资源
    最近更新 更多