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/

相关文章:

python - ImportError : matplotlib is required for plotting when the default backend "matplotlib" is selected

c - 为什么将数据写入以 O_APPEND 标志打开的文件,总是写在末尾,即使是 `lseek` ?

git - 一个用于多项目 git 存储库的 Jenkinsfile

git - 是否有将在分支删除后运行的 git Hook ?

ruby-on-rails - 每次推送到 heroku 时都需要重置数据库吗?

linux - 如何使用 sed 提取子字符串

linux - 如何在 linux 驱动程序模块中暂停 100 多毫秒?

mysql - 从远程机器连接到 MySQL

git - 为什么我应该在 Git 中使用 core.autocrlf=true?

git - 为什么我不能在 Windows 7 上安装 TortoiseGit 1.6.3.0?