gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 09:18:27 24 4
gpt4 key购买 nike

我的工作目录 /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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com