3

I have a Git repository that contains a .gitignore file, which lists a few files (that are created during the build) to be ignored.

$ cat .gitignore
foo
$ ls
bar
$ git status
On branch master
nothing to commit, working directory clean
$ touch foo
$ ls
bar foo
$ git status
On branch master
nothing to commit, working directory clean
$

In a specific clone of that repository, I do want to see the files listed in .gitignore.

This can be done with the --ignored option to git status:

$ git status
On branch master
nothing to commit, working directory clean
$ git status --ignored
On branch master
Ignored files:
  (use "git add -f <file>..." to include in what will be committed)

    foo

nothing to commit, working directory clean
$

Nice. My question is: how can I make this permanent for a given repository, so that I do not have to remember to add the --ignored flag?

$ git status
On branch master
Ignored files:
  (use "git add -f <file>..." to include in what will be committed)

    foo

nothing to commit, working directory clean
$

I'm sure there is some git configuration that allows me to configure my clone to ignore the contents of .gitignore...

Also, I don't want to have this option for all repositories; only for a select few.

jub0bs
  • 60,866
  • 25
  • 183
  • 186
umläute
  • 28,885
  • 9
  • 68
  • 122

3 Answers3

1

What you need to do is create an alias (let's call it istatus) for $ git status command.

$  git istatus
On branch master
Ignored files:
  (use "git add -f <file>..." to include in what will be committed)

    foo

nothing to commit, working directory clean

How to do it is described here and even there's a similar question on SO.

TL;DR: Basically you just need to add lines to ~/.gitconfig:

[alias]
    istatus = status --ignored
Community
  • 1
  • 1
Kleskowy
  • 2,648
  • 1
  • 16
  • 19
  • hmm, i'm really looking for a solution that does not require *me to remember* anything special about the given repository. – umläute Sep 18 '14 at 10:23
  • Look at the accepted answer to [this question regarding shadowing aliases on SO](http://stackoverflow.com/questions/5916565/define-git-alias-with-the-same-name-to-shadow-original-command) – Kleskowy Sep 18 '14 at 10:27
  • You're missing a "d" at the end; it should be `git status --ignored`. – jub0bs Sep 21 '14 at 11:14
1

Not possible (yet)

Git (at least v2.1 and older) does not allow you to configure git status to also list ignored files by default.

What Git does allow you to do, though, is modify the behavior of git status with respect to untracked file via the status.showUntrackedFiles option.

Perhaps a future version of Git will feature a "status.showIgnoredFiles" option...

So, what can you do?

1 - Define a alias locally

The obvious and probably best thing to do would be, as suggested by Kleskowy in his answer, to define an alias local to your repository:

git config alias.istatus "status --ignored"

Then, running git istatus instead of git status in the repository in question would also list ignored files.

2 - Define a small wrapper around git

Caveat: The following approach applies at the user level, not at the repository level.

Alternatively, if you're not averse to having a small wrapper around git, you can define the following, which automatically uses the --ignored flag when git status is run:

git() {
    if [[ ($1 == "status") ]]; then
        command git status --ignored "${@:2}";
    else
        command git "$@";
    fi;
}

Put those lines in your .<shell>rc file and source the latter.

Here is the result of a test (in bash) of that wrapper in one of my repositories:

enter image description here

Note that ignored files also get listed, even though the --ignored flag is not used explicitly.

Conclusion

Unless someone can think of a better approach, what you're asking is essentially a feature request for Git; therefore, I'm not sure your question has its place here...

Community
  • 1
  • 1
jub0bs
  • 60,866
  • 25
  • 183
  • 186
  • this is nice if you want that behaviour for *all* repositories. i'm really interested in a solution that is configurable *per-repo*. – umläute Sep 19 '14 at 07:15
0

none of the proposed solutions did what i actually wanted.

however, @Jubobs suggestion of a wrapper function finally gave me the idea of how to actually do it.

outline

  • flag a given repository for the change, preferrably using the git way. this can be accomplished using git config and some user defined variable

  • why stop with adding a single option (--ignored) to a single command (status)? it would be nice if we could pass default arguments for each git command,

implementation

so i ended up with the following little snippet, to be sourced at startup:

git() {
  local GIT=$(which git)
  case "x$1" in
    x|xconfig)
      ${GIT} "$@"
    ;;
    *)
      ${GIT} $1 $(${GIT} config --get $1.options) "${@:2}"
    ;;
  esac
}

so in my special repository, i simply do:

$ git config --add status.options "--ignored"

after that, running the following command in this repo will show me even ignored files, while other repositories will behave as usual.

$ git status

discussion

  • you can add your personal options to any git command by creating a config-option named ${cmd}.options. e.g. if you prefer to decorate your git log output, simply do:

    $ git config log.options "--decorate"
    
  • the script excludes the config subcommand for safety reasons. this should prevent shooting yourself in the knee with something like:

    $ git config add config.options --fuzz
    
  • finally, it uses some bashisms (namely ${@:2}) to allow for arguments containing whitespace; if your shell is not bash, take care...

umläute
  • 28,885
  • 9
  • 68
  • 122