Reputation: 11171
I have a site that has a /sites/default/files/
directory where user content is typically kept. Figuring that I don't need to be tracking this stuff, I added /sites/default/files/ to my .gitignore file.
Then I discovered that I also wanted to keep some mostly-permanent uploads in that directory as well. Now it makes more sense to track everything in /sites/default/files/ and exclude undesirable subdirectories, instead of doing it the other way around.
The problem is that Git won't stop ignoring that directory. I have removed the lines from .gitignore that specify this directory and it won't track it. I have the option to use git add /sites/default/files/ -f
to force git to track the directory, but I've done that before and it seems messy.
If .gitignore no longer specifies that directory as ignored, why would I have to force Git to start tracking those files?
Upvotes: 84
Views: 50300
Reputation: 31
If you mistakenly click on ignored option ion Eclipse git through git staging, then to get back your file do following things:
git status --ignored
execute this cmd here your ignored file will displayedgit add -f <file path>
[add file path after -f ]git status
Upvotes: 3
Reputation: 501
In my case, .png
and .xlsx
files were ignored in the repo. As @doub1ejack, @J-16 SDiZ, and others stated, you need to use git add -f
to track the changes. However, git add -f
does not work unless you specify the files or patterns explicitly and responds as
Nothing specified, nothing added.
Maybe you wanted to say 'git add .'?
In order to start tracking previously ignored files or patterns:
cd <path>
.git add -f <file name>.extension
for a specific file or git add -f *.xlsx
for all excel files.This unignored the ignored files for my case. You can also check this YouTube video.
Upvotes: 1
Reputation: 1264
We had a very similar problem in our Drupal sites directory. The issue is that the Drupal distribution has a .gitignore file in the higher level drupal directory that matches anything in drupal/sites/files/*
Upvotes: 2
Reputation: 11171
For posterity: the answer to my problem was "just look closer".
@twalberg pointed out, correctly, that there might be a rule I was overlooking in the .gitignore file. The cascading manner in which the .gitignore rules are applied make it easy to exclude files more broadly than intended.
As far as I can tell, the assumptions I was making about how git works were correct. Similarly, my case doesn't seem to support (or disprove) @J-16 SDiZ 's comments on what role the assume-unchanged
bit may play.
Upvotes: 11
Reputation: 2151
I don't think J-16 is correct. From http://www.kernel.org/pub/software/scm/git/docs/git-add.html:
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.
git add -f
seems to only be for adding a file that does exist in an ignore file somewhere.
Perhaps there is another .gitignore file in /sites or /sites/default which is also telling Git to ignore this dir, or maybe it's been set in .git/info/exclude?
Upvotes: 13
Reputation: 26910
You know how to do it already. Yes, git add -f
is the way.
If you ask why... this is because git set a assume-unchanged
bit internally. This bit make git think the file is not modified, so git add
won't add it.
If you want to mess with the implementation details, you can use git update-index --no-assume-unchanged <file>
command.
Upvotes: 84