我已经运行了以下命令来忽略监视/跟踪特定的目录/文件:

git update-index --assume-unchanged <file>

我如何撤销这一点,以便<文件>再次被监视/跟踪?


当前回答

在Windows中没有一个解决方案对我有效-它似乎使用大写H而不是H来表示文件状态,grep命令需要一个额外的插入符号,因为^也表示行开始以及否定下一个字符。

Windows的解决方案

Open Git Bash and change to the relevant top level directory. git ls-files -v | grep '^^H' to list all the uncached files git ls-files -v | grep '^^H' | cut -c 3- | tr '\012' '\000' | xargs -0 git update-index --no-skip-worktree to undo the files skipping of all files that was done via update-index --skip-worktree git ls-files -v | grep '^^H]' | cut -c 3- | tr '\012' '\000' | xargs -0 git update-index --no-assume-unchanged to undo the files skipping of all files that was done via update-index --assume-unchanged git ls-files -v | grep '^^H' to again list all the uncached files and check whether the above commands have worked - this should now not return anything

其他回答

在Windows中没有一个解决方案对我有效-它似乎使用大写H而不是H来表示文件状态,grep命令需要一个额外的插入符号,因为^也表示行开始以及否定下一个字符。

Windows的解决方案

Open Git Bash and change to the relevant top level directory. git ls-files -v | grep '^^H' to list all the uncached files git ls-files -v | grep '^^H' | cut -c 3- | tr '\012' '\000' | xargs -0 git update-index --no-skip-worktree to undo the files skipping of all files that was done via update-index --skip-worktree git ls-files -v | grep '^^H]' | cut -c 3- | tr '\012' '\000' | xargs -0 git update-index --no-assume-unchanged to undo the files skipping of all files that was done via update-index --assume-unchanged git ls-files -v | grep '^^H' to again list all the uncached files and check whether the above commands have worked - this should now not return anything

为了综合来自@adardesign, @adswebwork和@AnkitVishwakarma的优秀原始答案,以及来自@Bdoserror, @Retsam, @seanf和@torek的评论,以及额外的文档链接和简洁的别名……

基本命令

将一个假设不变的文件重置为正常状态。

git update-index --no-assume-unchanged <file>

列出所有假设不变的文件:

git ls-files -v | grep '^[a-z]' | cut -c3-

重置所有未修改的文件。

git ls-files -v | grep '^[a-z]' | cut -c3- | xargs git update-index --no-assume-unchanged --

注意:这个已经在其他地方列出的命令似乎不再重置所有假设不变的文件(我相信它曾经和以前列出它作为一个解决方案):

git update-index --really-refresh

快捷键

为了让这些常见的任务更容易在git中执行,为您的用户在.gitconfig中添加/更新以下别名部分(例如~/。*nix或macOS系统上的gitconfig):

[alias]
    hide = update-index --assume-unchanged
    unhide = update-index --no-assume-unchanged
    unhide-all = ! git ls-files -v | grep '^[a-z]' | cut -c3- | xargs git unhide --
    hidden = ! git ls-files -v | grep '^[a-z]' | cut -c3-

Git update-index函数有几个选项,你可以输入如下:

git update-index --help

在这里你会发现各种选项-如何处理函数update-index。

[如果你不知道文件名]

git update-index --really-refresh 

[如果你知道文件名]

git update-index --no-assume-unchanged <file>

将恢复所有已添加到忽略列表中的文件。

git update-index --assume-unchanged <file>

添加到@adardesign的答案中,如果你想一次性将所有已添加到假设不变列表中的文件重置为no-assume-unchanged,你可以执行以下操作:

git ls-files -v | grep '^h' | sed 's/^..//' | sed 's/\ /\\ /g' | xargs -I FILE git update-index --no-assume-unchanged FILE || true

这将从grep中删除输出的两个字符,即。"h ",然后转义文件名中可能出现的任何空格,最后|| true将防止命令在循环中的某些文件出现错误时过早终止。

要撤消/显示设置为assume-unchanged的dir's/files,执行以下命令:

git update-index --no-assume-unchanged <file>

要获得一个目录下的未修改的文件列表,运行以下命令:

git ls-files -v|grep '^h'