Can I get a list of files marked --assume-unchanged?
Asked Answered
P

5

391

What have I marked as --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. I've forgotten what I marked this way a few weeks ago and now I need to document those details for future developers.

Passant answered 2/3, 2010 at 13:0 Comment(0)
S
523

You can use 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. Edit your .gitconfig file to add this snippet:

[alias]
    ignored = !git ls-files -v | grep "^[[:lower:]]"

Now typing git ignored will give you output like this:

h path/to/ignored.file
h another/ignored.file
Scream answered 2/3, 2010 at 13:48 Comment(13)
Ah ha! Now that's what I was looking for. Thanks, Andrew. A quick alias/script should make it easy to retrieve a list limited to those files.Passant
git ls-files -v | grep ^[a-z]Bluh
My OS apparently has a weird collation setup, so Matt's command didn't work for me. Here's what I added under the [alias] section of my .gitconfig: ignored = !git ls-files -v | grep "^[[:lower:]]"Surfactant
Weird, yes, [a-z] has stopped working for me too! Abe's [[:lower]] does the job.Bluh
The reason [a-z] doesn't work is that the shell expands it as a wildcard; if the current directory contains a file that matches that pattern (ie a single lowercase letter), then the expansion of that is the name of the file. Try adding quotes, eg "[a-z]"Upholstery
@DomQ: No, that's not the (only) reason. I have the same problem, even with quotes: grep '^[a-z]'. The problem is indeed caused by the collation setup. I get this with LANG=en_US.UTF-8. With LANG unset or set to C, [a-z] works as expected.Gellman
git ls-files -v | grep -e "^[a-z]"Leblanc
The suggested aliases work for finding unchanged files at the current directory and below. If you want a list of all "assume-unchanged" files in the repository, you'll need git ls-files -v `git rev-parse --show-toplevel` | grep "^[a-z]"Cemetery
I couldn't get the default Mac OS X grep to work, what worked for me was using egrep instead. git ls-files -v | egrep "^[a-z]"Montmartre
output just file names: git ls-files -v | awk '$1~/[a-z]/{sub(/([^ ]* )/,"");print}'Anthill
@caiguanhao, my version to output only name: git ls-files -v | grep "^[[:lower:]]" | awk '{print $2}'Oilcloth
I would call the alias hide or show-hidden than ignored, since ignore may mean the ignored files defined in .gitignoreConvulsive
I don't really like this solution as for "skip-worktree" files, it is an uppercase S. :/Nosing
H
92

One Liner

git ls-files -v | grep "^[a-z]"

Use Aliases

IMHO, git hidden is better for files marked as --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:

[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:

-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:

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
Holeandcorner answered 7/5, 2016 at 2:34 Comment(3)
Nice easy-to-remember aliases :) ThanksTallbot
Here are some more flexible variants: hidden = "!f() { git ls-files -v \"$@\" | grep \"^[a-z]\"; }; f" and ignored = "!f() { git status -s --ignored \"$@\" | grep \"^!!\"; }; f". This allows, for example, git ignored -- PATH1 PATH2 to only list ignored files in certain paths (useful when you have a lot of ignored files).Corettacorette
Thank you for aliasBurnet
D
30

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.

Dispirit answered 15/4, 2015 at 23:29 Comment(1)
In the Windows prompt, use grep "^h" instead of single quotesSlapup
S
12

Windows command line solution using findstr:

git ls-files -v | findstr /B h
Seleucid answered 26/12, 2018 at 11:48 Comment(0)
W
9

PowerShell solution, using Select-String \ sls

git ls-files -v | sls -pattern ^h -casesensitive
Wadley answered 30/3, 2018 at 20:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.