3

I have a standard .gitignore file that I include in every project. One of the lines in there ignores "bin".

It so happens, in this particular project, I actually want a /bin directory. I removed "bin" from .gitignore, but git still won't let me add the /bin directory. It still thinks it should ignore it, even though the string has been removed from .gitignore.

All the answers I'm finding are about how to ignore something previously committed, but I'm not finding any info on how to add something previously ignored.

So: How do I tell git to unignore something previously ignored?

Warren Benedetto
  • 2,478
  • 2
  • 22
  • 25

3 Answers3

3
  • Ensure your .gitignore does not ignore the bin directory anymore. To confirm you can run git ls-files . --ignored --exclude-standard --others from the root of your repo to list all the files ignored by git.

  • Another way to do the same is if you try add the bin directory using git add without giving a -f argument, git would complain that the files are currently being ignored. If you do see this message you still have a .gitignore somewhere which seems to cause git to ignore the bin directory.

  • Also remember that git does not version empty directories. You need to have at least a single file under a directory for git to track it under version control. In that case create a dummy file under the bin directory and that file say git add bin/.dummy. This way you ensure that the bin directory is created on a clone or a checkout.

UPDATE based on your comments:

  • The .gitignore files can be present at multiple directories in the repository to include or exclude rules for different directory levels. From the root of your repo, run find . -type f -name .gitignore to see if you have any other gitignore files in your repo.

There is also a global way to specify gitingore using the following git configuration option, check to see if such a config exists in your setup:

git config --global --get core.excludesfile
Tuxdude
  • 47,485
  • 15
  • 109
  • 110
  • Hmm. Great answer. Unfortunately, none of those suggestions panned out. I wasn't aware of the global gitignore via git config. Seemed like a likely solution, but it turned out that "bin" isn't in there. The git ls-files suggestion returned nothing. There are files in the bin dir. There's only one gitignore in the project. – Warren Benedetto Mar 20 '13 at 09:05
  • @WarrenBenedetto - In addition to looking under `.git/info/exclude`, you might want to look at the following 2 config options `git config --get --local core.excludesfile` and `git config --get --global core.excludesfile` to see if some other file is meant to be used as the gitignore file. – Tuxdude Mar 21 '13 at 04:00
  • I figured it out. I had removed bin from .gitignore, but I didn't notice [Bb]in until now. That explains it. Thanks for your help! – Warren Benedetto Mar 21 '13 at 04:56
2

Most likely you have a global git ignore file - in ~/.gitignore typically. You can check for this with:

-> git config core.excludesfile 
/home/andy/.gitignore

You can invert the ignore rule, or the simplest solution is to just add the bin files and move on:

git add -f bin
git commit -m "Adding my bin files"
AD7six
  • 63,116
  • 12
  • 91
  • 123
  • The global gitignore is obtained using the global config option `core.excludesfile` and can be anything other than `~/.gitignore` as well ;) – Tuxdude Mar 20 '13 at 08:39
  • 1
    I just wanted to point out a correction. The first version of your answer (before the edit) did not mention anything about `core.excludesfile`. But now it does not matter, since you've added that part to your answer already. – Tuxdude Mar 20 '13 at 08:50
0

Note too sure what you mean by it is still 'ignoring' it. You mean when you type 'git status' the bin/ directory doesn't show up as untracked or modified?

Try explicitly adding it to git perhaps?

git add bin/
git commit -m "Adding the bin directory"
Derek Gourlay
  • 279
  • 2
  • 13
  • $ git add bin/ The following paths are ignored by one of your .gitignore files: bin Use -f if you really want to add them. fatal: no files added – Warren Benedetto Mar 20 '13 at 08:27
  • Using -f works, but I'm still curious why it thinks 'bin' is in .gitignore when it has been removed. Feels like there should be some command to reload/refresh .gitignore or something, but I don't see anything like that. – Warren Benedetto Mar 20 '13 at 08:28
  • https://help.github.com/articles/ignoring-files has some helpful info. I would suggest you take a look into your global ignore file. – Derek Gourlay Mar 20 '13 at 08:37