这两个东西是一样的吗?如果是,为什么有这么多术语?!
此外,我知道有一个叫做 Git Stash 的工具,可以在不提交到仓库的情况下将更改暂时存储到你的本地副本中。我觉得这个工具非常有用,但是它的名称与 Git 中的一堆其他概念非常相似,这非常令人困惑!!
这两个东西是一样的吗?如果是,为什么有这么多术语?!
此外,我知道有一个叫做 Git Stash 的工具,可以在不提交到仓库的情况下将更改暂时存储到你的本地副本中。我觉得这个工具非常有用,但是它的名称与 Git 中的一堆其他概念非常相似,这非常令人困惑!!
stash
功能是一种储存“正在进行中”的工作, 而你现在不想提交到特定存储区域(一个commit对象),基本的 stash
命令将存储对工作目录进行的未提交更改(包括缓存/阶段和未缓存/未暂存的更改),然后回滚工作目录到HEAD版本.stash
对象中的信息并将其应用于您的工作目录(即使工作目录本身处于不同的状态)。git stash
手册详细而易懂,并且有关于如何使用stash
的很好的示例。git ls-files --cached
返回的列表比git diff --cached --name-only
长得多?后者显示将包含在下一个提交中的文件,即已暂存的文件。 - Steve Pitchersgit ls-files --cached
显示被跟踪的文件以及索引/暂存区/缓存中的文件(--cache
选项是git ls-files
的默认行为)。我不确定这种行为的理由,但这就是它的作用。git diff --cached --name-only
只显示索引/暂存区/缓存中的文件。 - Michael Burr非常令人困惑。这三个术语可以互换使用。以下是我对为何称其为这些名称的看法。Git索引:
.git/index
,它是所有已跟踪文件的索引重要的一点是,索引/缓存/暂存区包含源代码控制下的所有文件列表,即使是未更改的文件。不幸的是,像“将文件添加到索引”或“文件已暂存到索引”等短语可能会误导地暗示索引仅包含更改的文件。
以下是一个演示,显示git索引包含所有文件列表,而不仅仅是更改的文件:
# setup
git init
echo 'x' > committed.txt
git add committed.txt
git commit -m 'initial'
echo 'y' > staged.txt
git add staged.txt
echo 'z' > working.txt
# list HEAD
git ls-tree --name-only -r HEAD
# committed.txt
# list index
git ls-files
# committed.txt
# staged.txt
# raw content of .git/index
strings .git/index
# DIRC
# committed.txt
# staged.txt
# TREE
# list working dir
ls -1
# committed.txt
# staged.txt
# working.txt
额外阅读:
https://www.kernel.org/pub/software/scm/git/docs/technical/racy-git.txt
ls -1
是有效的,并且与他粘贴的输出匹配。(man页面: "-1
强制每行输出一个条目。" vs "-l
以长格式列出。") - boweebstrings -n 3
会打印出来,但您也会得到一些垃圾信息。 - Zach Younghttps://dev59.com/0mw15IYBdhLWcg3wSJo3#6718135
索引文件:
来自man git
:
$GIT_INDEX_FILE
设置索引文件。
如果未指定,
将使用$GIT_DIR/index
。
当使用名为fugitive
的插件在nvim中打开时:
内容与git status
的输出非常相似,而不是strings .git/index
1.
-c, --cached ( cache: obsolete for index)
Show cached files in the output
(default)
-s, --stage
Show staged (git add) files'
mode bits,
object name
stage number
-u, --unmerged
(forces --stage)
Show unmerged files in the output
-d, --deleted
-m, --modified
-k, --killed
Show files on the filesystem
that need to be removed due to
file/directory conflicts
for checkout-index to succeed.
2.
-o, --others
other (i.e. untracked) files
--directory
If a whole directory is classified as "other",
show just its name (with a trailing slash)
and not its whole contents.
--no-empty-directory
Do not list empty directories.
Has no effect without --directory.
https://github.blog/2021-11-10-make-your-monorepo-feel-small-with-gits-sparse-index/