Reputation: 4239
Basically, I have the following folder structure:
repo
README.md
testing_folder
readingme.md
resources_folder
And in my .gitignore file
, I want to ignore all files except folders in current directory and this is what I have :
*
!.gitignore
!*/
When I do git status
, this is what I get:
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: .gitignore
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: .gitignore
modified: README.md
Problem is: it doesn't show that the testing_folder
and resources_folder
are untracked
. And when I try to do git add testing/readingme.md
, I got the following error message:
The following paths are ignored by one of your .gitignore files:
testing/readingme.md
Use -f if you really want to add them.
fatal: no files added
I am starting to get really confused now because I have read so many other related posts. They seem to work but mine just doesn't work.
I tried including and excluding the !*/
statement in .gitignore file but still the folders are not shown as untracked
.
Upvotes: 0
Views: 127
Reputation: 322
I've recreated the directory structure you showed in the post, and when my .gitignore
contains:
/*
!*/
!.gitignore
I did notice that when the first line was *
instead of /*
I had the same problem as you. Adding the /
, I would guess, gives git enough context to do what you want. With the /*
my git status
returns:
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: .gitignore
Untracked files:
(use "git add <file>..." to include in what will be committed)
testing_folder/
This will, essentially, only track files which aren't in the parent directory. The reason why resources_folder
isn't showing up is because git doesn't track empty directories. There are some ways to trick git into tracking empty folders, but it's not default behavior.
Upvotes: 2