386

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.

blahdiblah
  • 33,069
  • 21
  • 98
  • 152
Rob Wilkerson
  • 40,476
  • 42
  • 137
  • 192

5 Answers5

518

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
Patrick M
  • 10,547
  • 9
  • 68
  • 101
Andrew Aylett
  • 39,182
  • 5
  • 68
  • 95
  • 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. – Rob Wilkerson Mar 02 '10 at 13:55
  • 47
    git ls-files -v | grep ^[a-z] – Matt R May 07 '10 at 15:39
  • 18
    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:]]"` – Abe Voelker Sep 03 '11 at 22:55
  • Weird, yes, [a-z] has stopped working for me too! Abe's [[:lower]] does the job. – Matt R Oct 13 '11 at 11:30
  • 15
    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]" – DomQ Mar 09 '12 at 13:10
  • 1
    @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. – sleske Sep 21 '12 at 14:01
  • 8
    git ls-files -v | grep -e "^[a-z]" – Amir Ali Akbari Apr 01 '13 at 10:17
  • 15
    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]"` – Trebor Rude May 15 '13 at 15:43
  • 1
    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]"` – Silas Paul Apr 02 '14 at 18:08
  • 1
    output just file names: `git ls-files -v | awk '$1~/[a-z]/{sub(/([^ ]* )/,"");print}'` – caiguanhao Oct 02 '14 at 08:18
  • 1
    @caiguanhao, my version to output only name: `git ls-files -v | grep "^[[:lower:]]" | awk '{print $2}'` – Roy Ling Jan 14 '16 at 05:50
  • 2
    I would call the alias `hide` or `show-hidden` than `ignored`, since `ignore` may mean the ignored files defined in `.gitignore` – Robin Hsu Sep 21 '18 at 10:00
  • I don't really like this solution as for "skip-worktree" files, it is an uppercase S. :/ – Alexis Paques Dec 07 '21 at 07:40
91

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
ryenus
  • 15,711
  • 5
  • 56
  • 63
  • 2
    Nice easy-to-remember aliases :) Thanks – Debajit Jun 29 '16 at 20:56
  • 1
    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). – sls Jul 13 '16 at 08:05
  • Thank you for alias – MOHRE May 17 '17 at 06:11
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.

earl3s
  • 2,393
  • 1
  • 23
  • 24
10

Windows command line solution using findstr:

git ls-files -v | findstr /B h
Volodymyr
  • 1,209
  • 1
  • 15
  • 26
9

PowerShell solution, using Select-String \ sls

git ls-files -v | sls -pattern ^h -casesensitive
Thowk
  • 386
  • 4
  • 15