1

So I've looked around and understand how to add an ignored directory to a git repo, however all of these methods seem to me to result in every file in that directory being added, even those that should still really be ignored.

E.G. I have an ignored directory called dir/ and I want to add source contained (.cpp etc) to the git repo, while still applying the .gitignore file to items in that directory (i.e. continue ignoring .o files etc). The command that I think should work is:

git add --all /path/to/dir/*

This, however, also adds files which I still want ignored (.o etc).

Anyone have any thoughts on this? Thanks in advance for the help!

Ben Turner
  • 725
  • 1
  • 6
  • 23
  • You can also take a look here to block ignored files on the server/client without .gitignore : http://stackoverflow.com/questions/35400416/what-are-some-more-forceful-ways-than-a-gitignore-to-keep-files-out-of-a-repo/35400472#35400472 – CodeWizard Feb 16 '16 at 16:24

1 Answers1

1

This indicates one of two things:

  • your .gitignore is not set up properly
  • you are trying to retroactively ignore the directory

man gitignore says this:

A gitignore file specifies intentionally untracked files that Git should ignore. Files already tracked by Git are not affected; see the NOTES below for details.

The purpose of gitignore files is to ensure that certain files not tracked by Git remain untracked.

To stop tracking a file that is currently tracked, use git rm --cached.

There is a question on Stackoverflow that gives you a more complex command, but I think the accepted answer is dangerous, so I will not link to it

Now, the biggest indication that your .gitignore is not set up properly or applying the files you want untracked is given by man git add:

The git add command will not add ignored files by default. If any ignored files were explicitly specified on the command line, git add will fail with a list of ignored files. Ignored files reached by directory recursion or filename globbing performed by Git (quote your globs before the shell) will be silently ignored. The git add command can be used to add ignored files with the -f (force) option.

Community
  • 1
  • 1
smileyboy
  • 11
  • 1
  • This is all true, and I completely agree, however in some instances (for example I am working on an embedded project) you may wish for specific directories to not be ignored (e.g. the embedded devices root file system which will contain .so files etc that would normally be ignored, but in this specific case you want added to the repo. – Ben Turner Feb 17 '16 at 08:58