Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux “我该怎么做?”;摘录;我提交的文件?_Linux_Git - Fatal编程技术网

Linux “我该怎么做?”;摘录;我提交的文件?

Linux “我该怎么做?”;摘录;我提交的文件?,linux,git,Linux,Git,我的工作目录/tmp/working中有两个文件file1.c和file1.h。我所做的一切都在本地文件系统上 我在/tmp/working中执行git init,在其中创建一个.git目录。然后我git add file1.*和git commit-m“2017年2月13日” 2月17日,我无意中删除了我工作目录中的两个文件。如何从本地git存储库恢复工作目录中的文件?我不想撤消上次提交或类似的操作,只想将我的文件副本(2月13日的版本)放回我的工作目录。您可以尝试从最新提交中检出这两个文件:

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

我在
/tmp/working
中执行
git init
,在其中创建一个
.git
目录。然后我
git add file1.*
git commit-m“2017年2月13日”


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

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

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

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

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

您是否使用
git rm
删除?能否将git状态的输出添加到问题中?将存储库存储在
/tmp
中似乎有风险,它可能会在重新启动时被删除。是否使用
git rm
删除?您可以将git状态的输出添加到问题中吗?将存储库存储在
/tmp
中似乎有风险,它可能会在重新启动时被删除。更一般地说,您可以通过运行:
git checkout[branch\u or\u commit]在任何其他提交中获取文件内容--path/to/file
如何在不单独指定每个文件名的情况下提取文件?将提交的所有文件的最新版本从本地存储库还原到我的工作目录?类似于arj x archive.arjAnd更一般地说:您可以通过运行以下命令在任何其他提交中获取文件内容:
git checkout[branch\u or\u commit]--path/to/file
如何在不单独指定每个文件名的情况下提取文件?将提交的所有文件的最新版本从本地存储库还原到我的工作目录?类似于arj x archive.arj的东西