本文翻译自:Can I get a list of files marked --assume-unchanged?
What have I marked as --assume-unchanged
? 我标记--assume-unchanged
? Is there any way to find out what I've tucked away using that option? 有没有办法找出我用这个选项隐藏的东西?
I've dug through the .git/
directory and don't see anything that looks like what I'd expect, but it must be somewhere. 我已经挖掘了.git/
目录,看不到任何看起来像我期望的东西,但它必须在某个地方。 I've forgotten what I marked this way a few weeks ago and now I need to document those details for future developers. 几周前我忘记了我用这种方式标记的内容,现在我需要为未来的开发人员记录这些细节。
#1楼
参考:https://stackoom.com/question/9um5/我可以获得标记为-assume-unchanged的文件列表吗
#2楼
You can use git ls-files -v
. 你可以使用git ls-files -v
。 If the character printed is lower-case, the file is marked assume-unchanged. 如果打印的字符是小写的,则文件标记为假设未更改。
To print just the files that are unchanged use: 要仅打印未更改的文件,请使用:
git ls-files -v | grep '^[[:lower:]]'
To embrace your lazy programmer, turn this into a git alias . 要拥抱懒惰的程序员,请将其转换为git别名 。 Edit your .gitconfig
file to add this snippet: 编辑.gitconfig
文件以添加此代码段:
[alias]
ignored = !git ls-files -v | grep "^[[:lower:]]"
Now typing git ignored
will give you output like this: 现在输入git ignored
会给你这样的输出:
h path/to/ignored.file
h another/ignored.file
#3楼
This command works more consistently for me. 这个命令对我来说更加一致。 It will print only the files that are listed as 'assume-unchanged'. 它将仅打印列为“假设未更改”的文件。
git ls-files -v|grep "^h"
I've used this lots of times in different environments and it works perfectly. 我已经在不同的环境中使用了很多次,它运行得很好。
#4楼
One Liner 一个班轮
git ls-files -v | grep "^[a-z]"
Use Aliases 使用别名
IMHO, git hidden
is better for files marked as --assume-unchanged
: 恕我直言,对于标记为--assume-unchanged
文件, git hidden
更好:
git config --global alias.hidden '!git ls-files -v | grep "^[a-z]"'
Here's a list of related aliases I have in ~/.gitconfig
: 这是我在~/.gitconfig
中的相关别名列表:
[alias]
hide = update-index --assume-unchanged
unhide = update-index --no-assume-unchanged
unhide-all = update-index --really-refresh
hidden = !git ls-files -v | grep \"^[a-z]\"
ignored = !git status -s --ignored | grep \"^!!\"
To make it work in subdirectories and support arguments : 使其在子目录和支持参数中工作 :
hidden = "!f(){ git -C \"$GIT_PREFIX\" ls-files -v \"$@\" | grep \"^[a-z]\";}; f"
ignored = "!f(){ git -C \"$GIT_PREFIX\" status -s --ignored \"$@\" | grep \"^!!\";}; f"
For example: 例如:
# cd target
# git ignored classes
About File Status 关于文件状态
For me most hidden files are marked with flag h
, though there're actually several other flags according to the manual of git-ls-files
-v
: 对我来说,大多数隐藏文件都标有标志h
,尽管根据git-ls-files
-v
手册实际上还有其他几个标志:
-v Similar to -t, but use lowercase letters for files that are marked as assume unchanged (see git-update-index(1)).
About git ls-files
-t
: 关于git ls-files
-t
:
This option (-t) identifies the file status with the following tags (followed by a space) at the start of each line: H cached S skip-worktree M unmerged R removed/deleted C modified/changed K to be killed ? other
#5楼
PowerShell解决方案,使用Select-String \\ sls
git ls-files -v | sls -pattern ^h -casesensitive
#6楼
使用findstr的 Windows命令行解决方案:
git ls-files -v | findstr /B h