puk
puk

Reputation: 16762

.gitignore not being recursively applied

End Goal: Have git recursively ignore files of type *.abc

Problem: Git

Description:

I have the following line in my gitignore top level file located at /home/alma/project-origin/.gitignore.

/**/*.abc

I issue the following commands and get the following output

cd /home/alma/project-origin/top-secret/subject
touch alma-wade.abc
git status .
On branch master
Untracked files:
  (use "git add <file>..." to include in what will be committed)

        alma-wade.abc

nothing added to commit but untracked files present (use "git add" to track)

to trouble shoot I create a .gitignore file in that folder and run it again

cd /home/alma/project-origin/top-secret/subject
touch alma-wade.abc
echo "*.abc" >> .gitignore
git status .
On branch master
Untracked files:
  (use "git add <file>..." to include in what will be committed)

        modified: .gitignore

nothing added to commit but untracked files present (use "git add" to track)

I removed the .gitignore local file (rm /home/alma/project-origin/top-secret/subject/.gitignore) and started trouble shooting

(A) Removing from cached

Source

cd /home/alma/project-origin/top-secret/subject
git rm -r --cached .
git commit -m "..."
git push origin master
#Successful push
git add .
git status .
On branch master
Untracked files:
  (use "git add <file>..." to include in what will be committed)

        alma-wade.abc

nothing added to commit but untracked files present (use "git add" to track)

(B) Checking file encoding

Source

file -bi /home/alma/project-origin/.gitignore
text/plain; charset=us-ascii

(C) Checking for trailing spaces

opened /home/alma/project-origin/.gitignore in vim and issued the command :set list and conducted a visual inspection

(D) Using git check-ignore -v

git check-ignore -v --no-index /home/alma/project-origin/top-secret/subject/alma-wade.abc
#no output
echo "*.abc" >> .gitignore
git check-ignore -v --no-index /home/alma/project-origin/top-secret/subject/alma-wade.abc
/home/alma/project-origin/top-secret/subject/.gitignore:1:*.abc       /home/alma/project-origin/top-secret/subject/alma-wade.abc
rm .gitignore

(E) Using git check-ignore -v from top level directory

This is the closest I have come to resolving this issue

cd /home/alma/project-origin/
echo "/**/*.abc" >> .gitignore
cd /home/alma/project-origin/top-secret/subject/
git check-ignore -v --no-index /home/alma/project-origin/top-secret/subject/alma-wade.abc
#No output
cd /home/alma/project-origin/
git check-ignore -v --no-index /home/alma/project-origin/top-secret/subject/alma-wade.abc
/home/alma/project-origin.gitignore:1:/**/*.abc       /home/alma/project-origin/top-secret/subject/alma-wade.abc

The top level .gitignore rule is applied when I do the check from the top level folder, but not when I am in a sub folder. I am at my wits end. The only thing I can think of is that this has something to do with the file system (cifs mounted). Could someone please help.

Upvotes: 2

Views: 385

Answers (2)

match
match

Reputation: 11060

If you want to ignore every occurrence of files ending .abc then you just want: *.abc - ** is mostly useful for matches which include subdirectory names in the match.

See https://www.atlassian.com/git/tutorials/gitignore for some examples on the ** syntax (and other globs).

For example:

$ git init test
$ cd test
$ mkdir -p 1/2
$ touch foo.txt 1/bar.txt 1/2/baz.txt
$ git status
On branch master

No commits yet

Untracked files:
(use "git add <file>..." to include in what will be committed)

1/
foo.txt

$ echo "*.txt" >.gitignore
$ git status
On branch master

No commits yet

Untracked files:
(use "git add <file>..." to include in what will be committed)

.gitignore

Upvotes: 2

Chris
Chris

Reputation: 136910

If you have nested Git repositories, a .gitignore in an "outer" repository will not affect "inner" repositories:

mkdir outer && cd outer
git init
echo '/**/*.txt/' > .gitignore
touch foo.txt
git status
# Untracked file '.gitignore'
# No mention of 'foo.txt'

mkdir inner && cd inner
git init
touch foo.txt
git status
# Untracked file 'foo.txt'

Since you have an inner repository that you do not appear to have created deliberately I recommend removing its .git/ directory (after making whatever backup you deem appropriate). This will make that directory's contents subject to the outer repository and the .gitignore should now take effect.

You will probably want to commit the files in the inner directory to the outer repository.

Upvotes: 1

Related Questions