0

Note: I have removed this question from duplicate because while using !run.sh works for me, i am looking to allow any file in ansible/files as well.(Any file that i might add in the future.) The other solutions for the same that i found did not work for me.

I want to exclude all .sh files from my repository, and for that i've used *.sh but then i want to include any file in ansible/files Currently, my .gitignore file looks like this:

# Ignore python environment
venv/

# Ignore .pyc files
*.pyc

# Ignore .log Files
*.log

# Ignore any __pycache__
__pycache__/

# Ignore .sh files
*.sh

# Allow any `.sh` file(s) in ansible/files folder
!/ansible/files/*.sh

# Allow any file(s) in ansible/files folder
!/ansible/files/*

But this isn't working, ansible/files/run.sh is a file that exists but doesn't get tracked. Question: Why is .gitignore ignoring !/ansible/files/*.sh & !/ansible/files/*; how to allow any file in that folder to be tracked?

Note: I have removed this question from duplicate because while using !run.sh works for me, i am looking to allow any file in ansible/files as well.(Any file that i might add in the future.) The other solutions for the same that i found did not work for me.

atb00ker
  • 957
  • 13
  • 24
  • Possible duplicate of [git ignore exception](https://stackoverflow.com/questions/3203228/git-ignore-exception) – phd Jan 09 '18 at 14:46
  • 1
    Do `git check-ignore -v ansible/files/run.sh` to see what rule matches that file. It's possible there's a `.gitignore` with an overriding rule in `ansible` or `ansible/files`, or perhaps there's some trailing whitespace on the paths. It's going to be something along these lines. – jthill Jan 09 '18 at 15:39

1 Answers1

1

You are probably missing a wildcard in front of the path. This is just an assumption but I doubt you ment to target (root)/ansible.

Try this:

# Allow any `.sh` file(s) in ansible/files folder
!*/ansible/files/*.sh

# Allow any file(s) in ansible/files folder
!*/ansible/files/*

Also, you have to change your rule for *.sh to the following:

# Ignore .sh files
*/*.sh
NullDev
  • 6,739
  • 4
  • 30
  • 54
  • If i do `*/*.sh` it doesn't ignore other `.sh` files in `app/scripts/prod/run.sh` (Includes the files i want to include but also any files in second-sub-directory of any folder.) – atb00ker Jan 09 '18 at 14:01