2

Please help me with a git ignoring.

I have files in the public/images directory and don't want to track them. But I need to track files in the /public/images/bonus2 directory. I used this code, and it works.

/public/images/
!/public/images/bonus2/

But when I try to move tracked files from public/images/bonus2 to public/images/bonus_ordering and make .gitignore like that:

/public/images/
!/public/images/bonus2/
!/public/images/bonus_ordering/

and make this command:

mv public/images/bonus2 public/images/bonus_ordering

git track that files in public/images/bonus2 removed, but it don't track that new files public/uploads/bonus_ordering appeared.

I used git add -f public/images/bonus_ordering, but I think that is not good solution. What I need to do instead of that?

Alex Antonov
  • 14,134
  • 7
  • 65
  • 142
  • Would that have worked better if you did a `git mv` instead of an `mv`? Also http://stackoverflow.com/a/20391855/6309 can be interesting to check. – VonC Dec 06 '13 at 06:46
  • This may help: http://stackoverflow.com/questions/5533050/gitignore-exclude-folder-but-include-specific-subfolder - worth reading both top answers. – Chris Dec 06 '13 at 09:24

1 Answers1

0

You should add the changed .gitignore file and commit it first to take effect.

git add .gitignore
git commit -m "update gitignore"
mv your_file your_new_location
git add .
git commit -m "files moved"

Edit: As JonC points out, you don't need to commit the .gitignore file. Adding it is enough for it to take effect.

Munim
  • 6,310
  • 2
  • 35
  • 44
  • Change it first: yes. And and commit, no. You don't need to add and commit for a `.gitignore` to be taken into account right away. But it is still a good idea in order to not loose your modifications on the `.gitignore` file. – VonC Dec 06 '13 at 11:28
  • @VonC I actually had a doubt about that. But I answered with commit to be on the safer side. – Munim Dec 06 '13 at 13:02