簡體   English   中英

為什么`git update-index`不會影響不在當前目錄中的文件?

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

我正在嘗試再次使用git update-index --again -- 將修改后的文件重新添加到索引中。 這工作正常,但僅適用於當前目錄中的文件/目錄。 這是該命令的預期行為還是有任何選項可以使其考慮整個存儲庫?

這看起來(在我的測試中)就像任何典型的 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運行 find 或工作樹頂部的任何內容。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM