git 我可以获得标记为 --assume-unchanged 的文件列表吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2363197/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can I get a list of files marked --assume-unchanged?
提问by Rob Wilkerson
What have I marked as --assume-unchanged
? Is there any way to find out what I've tucked away using that option?
我标记了--assume-unchanged
什么?有什么方法可以使用该选项找出我隐藏的内容吗?
I've dug through the .git/
directory and don't see anything that looks like what I'd expect, but it must be somewhere. I've forgotten what I marked this way a few weeks ago and now I need to document those details for future developers.
我翻遍了.git/
目录,没有看到任何看起来像我期望的东西,但它一定在某个地方。我已经忘记了几周前我以这种方式标记的内容,现在我需要为未来的开发人员记录这些详细信息。
回答by Andrew Aylett
You can use git ls-files -v
. If the character printed is lower-case, the file is marked assume-unchanged.
您可以使用git ls-files -v
. 如果打印的字符是小写,则文件被标记为假定未更改。
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. Edit your .gitconfig
file to add this snippet:
为了拥抱你的懒惰程序员,把它变成一个git alias。编辑您的.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
回答by ryenus
One Liner
一个班轮
git ls-files -v | grep "^[a-z]"
Use Aliases
使用别名
IMHO, git hidden
is better for files marked as --assume-unchanged
:
恕我直言,git hidden
更适合标记为--assume-unchanged
:
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 subdirectoriesand 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 hiddenfiles are marked with flag h
, though there're actually several other flags according to the manual of git-ls-files
-v
:
对我来说,大多数隐藏文件都标有 flag 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)).
-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
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
回答by earl3s
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.
我已经在不同的环境中多次使用过它,并且效果很好。
回答by Thowk
PowerShell solution, using Select-String \ sls
PowerShell 解决方案,使用Select-String\sls
git ls-files -v | sls -pattern ^h -casesensitive
回答by Vova
Windows command linesolution using findstr:
使用findstr 的Windows 命令行解决方案:
git ls-files -v | findstr /B h