为什么 refs/stash 不包含未跟踪的文件? [已关闭]

问题描述 投票:0回答:1

git stash
创建一项包含暂存更改的提交 (
refs/stash^2
)、一项包含未跟踪文件的无父提交 (
refs/stash^3
)(仅使用选项
--include-untracked
)以及一项包含暂存和未暂存更改的提交这是前两者和 HEAD 的合并 (
refs/stash
)。

$ git log --graph --all --oneline
*-.   bcfa2f3 (refs/stash) WIP on develop: 4500b25 init
|\ \
| | * 6090318 untracked files on develop: 4500b25 init
| * e41cc92 index on develop: 4500b25 init
|/
* 4500b25 (HEAD -> develop) init

使用选项

refs/stash
时,为什么
--include-untracked
不包含未跟踪的文件,即使未跟踪的文件是存储的一部分?考虑到引用名为
refs/stash
stash
,这正是您所期望的,大概 是您在使用
git stash apply
时应用的内容。这也是您所期望的,因为
refs/stash
是由合并提交创建的,其中
refs/stash^3
作为父级之一。

此外,缺少诸如

--force
git stash apply
合并策略选项之类的内容会鼓励直接使用
refs/stash
,例如使用
git restore -s stash .
,除非您也这样做
git restore -s stash^3 myfile1 myfile2,否则不会获得未跟踪的文件
。如果您了解的话,您可以使用
git stash branch
,但是将更改更改到所需的分支需要一系列额外的步骤,这对于不太高级的 git 用户来说可能不太容易。

这是对直觉的严重违反,对于任何隐藏未跟踪文件的人来说,这可能迟早会导致问题。有什么道理吗?

git git-stash
1个回答
-1
投票

不分离未跟踪的文件将失去未跟踪的文件和新添加的文件之间的区别。

© www.soinside.com 2019 - 2024. All rights reserved.