Search code examples
gitcommand-line-interface

Is there a way in Git to list files that have been marked 'assume-unchanged'?


I ran into an issue with changed files not being detected by git status or git add, much the same as was answered here. The top answer there mentioned that the file(s) may have been marked as 'assume unchanged', which makes sense.

I'm curious if there's a good way in Git CLI to list all files in the index currently marked with this bit.

(Bonus: It would also be nice to be able to list files marked with the "skip-worktree" bit~)

Where I've already looked:

  • I checked the documentation for git update-index, finding no clues or further reading.
  • I also tried git help -a | grep index to look for any index-related commands that might be able to do what I'm asking. Not seeing any fruit here.

Solution

  • You can use the -v option to git ls-files:

    -v -- Similar to -t, but use lowercase letters for files that are marked as assume unchanged (see git-update-index(1)).

    So e.g., if I have a repository with a modified file, I might see something like this from git status:

    $ git status
    On branch main
    Your branch is up to date with 'origin/main'.
    
    Changes not staged for commit:
      (use "git add <file>..." to update what will be committed)
      (use "git restore <file>..." to discard changes in working directory)
            modified:   examplefile
    
    no changes added to commit (use "git add" and/or "git commit -a")
    

    If I mark that file as --assume-unchanged:

    $ git update-index --assume-unchanged examplefile
    

    Then git status now reports:

    On branch main
    Your branch is up to date with 'origin/main'.
    
    nothing to commit, working tree clean
    

    At this point, running git ls-files -v shows:

    H README.md
    h examplefile
    

    Note the lowercase h in front of examplefile. If I remove the assume-unchanged setting:

    $ git update-index --no-assume-unchanged examplefile
    

    Then git ls-files -v shows:

    $ git ls-files -v
    H README.md
    H examplefile