On the git stash manpage you can read (in the "Discussion" section, just after "Options" description) that:
(在git stash手册页上,您可以阅读(在“讨论”部分,在“选项”描述之后):)
A stash is represented as a commit whose tree records the state of the working directory, and its first parent is the commit at HEAD when the stash was created.
(存储表示为提交,其树记录工作目录的状态,其第一个父节点是创建存储时HEAD的提交。)
So you can treat stash (eg stash@{0}
is first / topmost stash) as a merge commit, and use:
(因此,您可以将stash(例如stash@{0}
是第一个/最顶层的存储)视为合并提交,并使用:)
$ git diff stash@{0}^1 stash@{0} -- <filename>
Explanation: stash@{0}^1
means the first parent of the given stash, which as stated in the explanation above is the commit at which changes were stashed away.
(说明: stash@{0}^1
表示给定存储的第一个父节点,如上面的解释中所述,是存储更改的提交。)
We use this form of "git diff" (with two commits) because stash@{0}
/ refs/stash
is a merge commit, and we have to tell git which parent we want to diff against. (我们使用这种形式的“git diff”(有两次提交),因为stash@{0}
/ refs/stash
是一个合并提交,我们必须告诉git我们要对哪个父进行区分。)
More cryptic: (更神秘:)
$ git diff stash@{0}^! -- <filename>
should also work (see git rev-parse manpage for explanation of rev^!
syntax, in "Specifying ranges" section).
(也应该工作(有关rev^!
语法的解释,请参阅git rev-parse手册页,在“指定范围”部分)。)
Likewise, you can use git checkout to check a single file out of the stash:
(同样,您可以使用git checkout从存储中检查单个文件:)
$ git checkout stash@{0} -- <filename>
or to save it under another filename:
(或者将其保存在另一个文件名下:)
$ git show stash@{0}:<full filename> > <newfile>
or
(要么)
$ git show stash@{0}:./<relative filename> > <newfile>
( note that here <full filename> is full pathname of a file relative to top directory of a project (think: relative to stash@{0}
)).
(( 请注意 ,此处<full filename>是相对于项目顶级目录的文件的完整路径名(想想:相对于stash@{0}
))。)
You might need to protect stash@{0}
from shell expansion, ie use "stash@{0}"
or 'stash@{0}'
.
(您可能需要保护stash@{0}
免受shell扩展,即使用"stash@{0}"
或'stash@{0}'
。)