如何在git存放区中签出未跟踪的文件? [英] How can I checkout an untracked file in a git stash?

查看:76
本文介绍了如何在git存放区中签出未跟踪的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我使用以下其中一种方法进行了一些更改:

Assume I have stashed some changes using one of:

git stash -u
git stash --include-untracked

我可以通过以下方式从存储中检出单个文件

I can checkout an individual file from the stash via

git checkout stash@{0} -- filename

如果git知道"filename",那么该方法有效,但是如果未跟踪"filename",则该方法无效.有什么方法可以从存储中检出未跟踪的文件?

That works if git knows about "filename", but doesn't work if "filename" is untracked. Is there any way to checkout untracked files from a stash?

推荐答案

git stash在内部创建特殊的黑魔法合并提交,以存储更改的不同部分.合并提交具有原始基础提交(存储时位于分支顶部的位置)作为其第一父提交,一个扔掉的提交代表存储时作为其第二父提交的索引内容,并且(仅当您使用--include-untracked)一个一次性提交,其中包含未跟踪的文件作为其第三父级.

git stash internally creates special black magic merge commits to store different parts of your changes. The merge commit has the original base commit (what you had at the top of the branch when you stashed) as its first parent, a throwaway commit representing the index contents at time of stashing as its second parent, and (only if you used --include-untracked) a throwaway commit containing the untracked files as its third parent.

因此,合并提交引用了未跟踪的文件(作为其父项之一)...但是实际上并没有将那些文件包括在自己的树中(如果这没有任何意义,则说明您已经还需要了解一些有关Git内部的东西...或者您对合并提交了解得太多,并且整个结构似乎太可怕了,无法考虑;)).

So, the merge commit references the untracked files (as one of its parents)... but it doesn't actually include those files in its own tree (if that doesn't make any sense, either you've got a few things to learn yet about Git's internals... or you know too much about merge commits and this whole construct just seems too horrible to think about ;)).

简而言之...要访问存储的未跟踪部分,请访问其第三个父级:git checkout stash@{0}^3 -- filename

In short... to access the untracked parts of your stash, access its third parent: git checkout stash@{0}^3 -- filename

这篇关于如何在git存放区中签出未跟踪的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆