Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.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
是否有一个git命令来检索文件的旧版本?_Git_Sh - Fatal编程技术网

是否有一个git命令来检索文件的旧版本?

是否有一个git命令来检索文件的旧版本?,git,sh,Git,Sh,在git中,我们可以使用git show commitlike:filepath以特定版本显示文件,使用shell重定向可以检索该版本并将其放回工作树中的某个位置:git show commitlike:filepath>otherpath 是否有一个git命令来执行后一个任务git checkout commitlike--filename可以检索文件,但只能将其放在原始位置 $ git config --global alias.getfile '!sh -c '"'"'git show $

在git中,我们可以使用
git show commitlike:filepath
以特定版本显示文件,使用shell重定向可以检索该版本并将其放回工作树中的某个位置:
git show commitlike:filepath>otherpath

是否有一个git命令来执行后一个任务
git checkout commitlike--filename
可以检索文件,但只能将其放在原始位置

$ git config --global alias.getfile '!sh -c '"'"'git show $1:$2 > $3'"'"' -'
然后你可以这样做:

$ git getfile COMMITLIKE FILE_PATH DESTINATION_FILE
例如:

$ git getfile HEAD~3 .gitignore old_gitignore

使用管道命令可能有一些聪明的方法,但是
git show
和重定向似乎是最明智的。可能的重复不是重复,我想将文件放回工作树中,而不是显示其内容。