git-checkout使用新名称的旧文件修订版 [英] git-checkout older revision of a file under a new name
问题描述
我的文件 main.cpp
在我的编辑器中打开。
我想查看之前在编辑器中也修改过 main.cpp
。
现在我这样做的方式就是这样。
在编辑器中关闭main.cpp
prompt> mv main.cpp tmp
prompt> git checkout HEAD ^ main.cpp
prompt> mv main.cpp old_main.cpp
prompt> mv tmp main.cpp
提示>
在编辑器中打开main.cpp和old_main.cpp
它可以被简化,所以我不必在编辑器中关闭main.cpp?
我所希望的是可以做到这一点的 git-checkout
的变体。
更新:im在mac osx 10.5.7上使用git
提示> git --version
git版本1.6.0.4
提示>
UPDATE2:JakubNarębski的答案是:
提示> git show HEAD ^:dir1 / dir2 / dir3 / main.cpp> old_main.cpp
提示>
UPDATE3:Karmi的回答,
提示> git show 4c274dd91dc:higgs / Higgs.xcodeproj / project.pbxproj> old_project.pbxproj
提示>
您可以使用git show / p>
提示> git show HEAD ^:main.cpp> old_main.cpp
(请注意冒号为:$ c $
和main.cpp`之间的字符。< revision> :< path> 的语法在 git rev-parse 联机帮助页,位于指定修订部分的最后一点旁边:
- < rev>:<路径>例如HEAD:README,:README,master:./ README $ b
后缀
:
后面跟着一个路径,指定在冒号前面部分命名的tree-ish对象中给定路径上的blob或tree。:path
(在冒号前有一个空的部分)是下面描述的语法的一个特例:记录在给定路径索引处的内容。
以
./
或../
是相对于当前的工作目录。给定的路径将被转换为相对于工作树的根目录。这对于处理与工作树具有相同树结构的提交或树来说是最有用的。
请注意,此处的<路径> 是 FULL 路径相对于顶部目录,即 如果要使用相对于当前目录的路径,则需要使用./<path>语法(或../<path>从当前目录上去)。 编辑2015-01-15: 在大多数情况下,级别(管道) I have the file " I want to see the previous revision of " The way I do it now is like this. Can it be simplified, so I don't have to close "main.cpp" in the editor? What I'm hoping for is a variant of UPDATE: im using git on mac osx 10.5.7
UPDATE2: Jakub Narębski answer is:
UPDATE3: Karmi's answer, for a specific revision:
You can use "git show" for that: (Note that there is colon ' .git /
目录的目录。 (或者更确切地说,< revision> (它通常可以是任何< tree-ish> ,即表示树的东西) p>
$ b
git cat-file
命令:
提示> git cat-file blob HEAD ^:main.cpp> old_main.cpp
main.cpp
" open in my editor.main.cpp
" in the editor too.close "main.cpp" in the editor
prompt> mv main.cpp tmp
prompt> git checkout HEAD^ main.cpp
prompt> mv main.cpp old_main.cpp
prompt> mv tmp main.cpp
prompt>
open "main.cpp" and "old_main.cpp" in the editor
git-checkout
that can do this.
prompt> git --version
git version 1.6.0.4
prompt>
prompt> git show HEAD^:dir1/dir2/dir3/main.cpp > old_main.cpp
prompt>
prompt> git show 4c274dd91dc:higgs/Higgs.xcodeproj/project.pbxproj > old_project.pbxproj
prompt>
prompt> git show HEAD^:main.cpp > old_main.cpp
:
' character between HEAD^
and main.cpp`.) The "<revision>:<path>" syntax is described in git rev-parse manpage, next to last point in the "Specifying revisions" section:
A suffix
:
followed by a path names the blob or tree at the given path in the tree-ish object named by the part before the colon.:path
(with an empty part before the colon) is a special case of the syntax described next: content recorded in the index at the given path.A path starting with
./
or../
is relative to the current working directory. The given path will be converted to be relative to the working tree’s root directory. This is most useful to address a blob or tree from a commit or tree that has the same tree structure as the working tree.
Note that "<path>" here is FULL path relative to the top directory of your project, i.e. the directory with .git/
directory. (Or to be more exact to "<revision>" (which in general can be any <tree-ish>, i.e. something that represents tree))
If you want to use path relative to the current directory, you need to use "./<path>" syntax (or "../<path>" to go up from current directory).
Edit 2015-01-15: added information about relative path syntax
You can get in most cases the same output using low-level (plumbing) git cat-file
command:
prompt> git cat-file blob HEAD^:main.cpp > old_main.cpp
这篇关于git-checkout使用新名称的旧文件修订版的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!