-3

I have a project with directory uploads/ which has subdirectories /images and /files. I want to ignore commiting files from these two subdirectories uploads/images and uploads/files but i want .gitignore file to be in root directory.

PYovchevski
  • 95
  • 1
  • 13
  • Just add those two to your `.gitignore` then. What is the problem, exactly? – Biffen Mar 10 '15 at 08:45
  • 1
    This is one of the most frequently asked questions in the [git](http://stackoverflow.com/questions/tagged/git) tag. Please make sure to search before submitting a new question. – Sascha Wolf Mar 10 '15 at 09:24
  • possible duplicate of [How to ignore all files in a folder with a git repository in SourceTree?](http://stackoverflow.com/questions/9665399/how-to-ignore-all-files-in-a-folder-with-a-git-repository-in-sourcetree) – Sascha Wolf Mar 10 '15 at 09:25

1 Answers1

1

Simply add in the .gitignore:

/uploads/images/
/uploads/files/

That will ignore the content of those folders, provided they were not already versioned.
If they were, you would need to remove them from the index and commit (recording the deletion from the repo, not from the disk: --cached)

git rm -r --cached uploads/images
git rm -r --cached uploads/files

but this ignore even the folders, not only content, I want to ignore only content of those folders

One trick is to ignore the all folder (as described above), and then do:

touch uploads/images/.keep
git add --force uploads/images/.keep
touch uploads/files/.keep
git add --force uploads/files/.keep
git commit -m "keep fodlers"

That means you need to have some content in order to keep the folder in the repo (an empty folder would not be tracked by Git).

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250