1

I have a git repository, with ignored paths specified in .git/info/exclude as they are specific to this clone. I wish to exclude a directory /foo (and everything below it) which is located at the root of the repository. However, I do not want to ignore /foo-x or /y/foo. I have played around with ignore patterns but cannot work out how to do this. Is it possible?

2 Answers 2

3

Try to add to .gitignore (for all users that will clone your repo) or .git/info/exclude (only for your machine) this:

/foo/

Note, that

Files already tracked by Git are not affected;

by gitignore. So, you should git rm them from the repo!

5
  • Unfortunately, this also ignores /foo-x. Feb 20, 2016 at 16:30
  • @AndrewHo I believe you're doing something wrong. I've checked it: $ cat .git/info/exclude: /data/ $ git status: # Untracked files: # (use "git add <file>..." to include in what will be committed) # # data-x
    – John_West
    Feb 20, 2016 at 16:38
  • @AndrewHo Does your foo-x contain even 1 file?
    – John_West
    Feb 20, 2016 at 16:43
  • You were right. I had the solution all along, but was careless when testing it! Feb 20, 2016 at 16:59
  • Can I add, make sure to include that leading /. If you don't then git will ignore all directories named foo even if they are not in the root. I've been learning that the hard way for months now! I just figure out the problem today.
    – z2k
    Jan 2, 2018 at 20:17
0

You can add it into .gitignore (for all) or .git/info/exclude (for you)

foo/

You can end patterns with a forward slash / to specify a directory.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .