linux - 我如何 "extract"我提交的文件?

标签 linux git

我的工作目录 /tmp/working 中有两个文件 file1.cfile1.h。我所做的一切都在我的本地文件系统上。

我在 /tmp/working 中执行了一个 git init,在其中创建了一个 .git 目录。然后我 git add file1.*git commit -m "Feb 13th 2017"

2 月 17 日,我不小心删除了工作目录中的两个文件。如何从我的本地 git 存储库恢复我工作目录中的文件?我不想撤消上次提交或类似的操作,只想将我的文件副本(2 月 13 日的版本)放回到我的工作目录中。

最佳答案

您可以尝试从最新提交中 check out 这两个文件:

git checkout -- path/to/file1.c
git checkout -- path/to/file1.h

Git 的好处在于很难真正把事情搞砸。您只在当前提交中本地删除了这两个文件。但是使用 git checkout 可以轻松访问他们的历史记录。


实际上,任何路径都有效:

git checkout -- path/to/    # extracts the whole "path/to" directory
git checkout -- .           # extract all the content of the last commit

您还可以指定任何提交:

git checkout other_branch -- path/to/   # extracts content from other_branch
git checkout v1.7.3 -- path/to/         #                  from this tag
git checkout eacf33b -- path/to/        #                  from this commit

关于linux - 我如何 "extract"我提交的文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44560049/

相关文章:

c - 为什么我得到 problem3.c :20:23: error: expected expression before ‘int’ ?

linux - 创建永久可执行别名

git - 提交到未 checkout 的分支

java - Git winmerge pop "select files and folders"出现

ios - 如何知道您的 cocoapod 安装指向哪个 pod 规范文件

linux - 配置文件的输入文件

linux - Python 3.6 无法在带有 "failed to get random numbers to initialize Python"的 QEMU 中构建

linux - Jenkins shell 字符串引用替换

c# - Visual Studio 在哪里存储发布配置文件?

git - 让 github 使用 .gitattributes "binary"属性