为什么 `git update-index` 不影响不在当前目录中的文件?

Why does `git update-index` not affect files not in the current directory?

我正在尝试使用 git update-index --again 将修改后的文件重新添加到索引中。这工作正常,但仅适用于当前目录中的 files/directories。这是此命令的预期行为,还是有任何选项可以让它考虑整个存储库?

这似乎(在我的测试中)就像任何典型的 git 命令一样工作。也就是说,它默认为当前工作目录和子目录(递归),如果你想要不同的东西,你可以指定路径。如果这不是您看到的行为,请提供更具体的说明,我可以再看一下。

例如

# setup a repo with some files
git init
touch file1
touch file2
mkdir dir
touch dir/file3
touch dir/file4
git add .
git commit -m "1"

# stage changes for a couple of the files, and make some additional changes
echo foo >file1
git add file1
echo bar >> file1
echo foo > file2
cd dir
echo foo >> file3
git add file3
git echo bar >> file3
git echo foo > file4

# now try it...
git update-index --again

因为我们在 dir 目录中,所以默认(与大多数采用路径的 git 命令一样)默认为当前目录。所以只有 file3 被重新安排 - 而不是 file1。但是如果我们说

git update-index --again :/:

这将从工作树的根应用命令。

请注意,从工作树顶部 运行 git 命令的一种方法是添加一个别名以在此处完成:

git config --global alias.attop '!git'

然后你可以 git attop update-index --again,我也有 !true; 作为别名所以我可以 git exec anycommand 到 运行 在工作树的顶部找到或任何东西.