0

I am using Ruby on Rails, the Capistrano gem and git. Long time ago I initialized git and in the .gitignore file I stated the following:

.bundle
db/*.sqlite3
log/*.log
tmp/

One day I created a sub-directory in the /public directory of my RoR application: /public/users/.... Now in the latter directory I have the following file system structure:

/public/users/001/file1.png
/public/users/001/file2.png
/public/users/001/file3.png
...
/public/users/002/file1.png
/public/users/002/file2.png
/public/users/002/file3.png
...
...

At this time git is tracking all file in the /public directory including all directories and files inside /public/users/. So, when I deploy with Capistrano, all those will be updated on the remote machine, as well.

What I would like to do is to do not track anymore public/users directories, subdirectories and files (on my local machine) so that on the remote machine those will be not updated. That is, I would like to make possible that when I deploy with Capistrano all that is related to the public/users (on the remote machine) is untouched.

How can I do that?

P.S.: I read a lot of other questions and answers (eg: 1, 2, ...) but all them seem do not work for me.


I am almost sure that I must add the following text line to the .gitignore file:

# Ignoring "public/users/" directories, sub-directories and files
public/users/

and then (if the above code is valid) what I should do?

Community
  • 1
  • 1
Backo
  • 18,291
  • 27
  • 103
  • 170
  • Note that git will not ignore files that it is already tracking. So after you edit your `.gitignore`, you also need to remove the files with `git rm` (`git rm --cached` if you want to keep the files around) and then commit. You can also do `git update-index --assume-unchanged`. – Tyler Sep 15 '11 at 07:15
  • @MatrixFrog - How should I use the `git update-index --assume-unchanged` command in my case? P.S.: I used the `git rm --cached` as described in posts I mentioned in my question but that seems do not work as expected. – Backo Sep 15 '11 at 07:29
  • `git update-index --assume-unchanged ` – Tyler Sep 15 '11 at 16:46

1 Answers1

1

Try to put all user related files into one folder , say system then You can put public/system/*.* in git ignore.. then your dir structure would be :

  public
      ->404.html
      ->js.../..,..,..
      ->css ../..,..,..
      ->system
         ->users
             ->1/something
             ->2/something 
         ->some-other-user-related-info

Also why is there a need to put development related files into git and then to server ?? No point .. so do not do it.. It will increase your repo size for no reason.

Since you are using capistrano your server dir structure will look like this :

APP
   ->Current
   ->releases
   ->shared

your public/system folder will keep pointing to shared/system

case 1: files in users/ not committed put all the user related file in .gitignore

case 2: if files have been commited perform a git delete and then commit then add it to .git ignore

Gaurav Shah
  • 5,223
  • 7
  • 43
  • 71
  • I have also other directories and files in the `public` directory (eg: `404.html`, `422.html`, `/images/`, `/javascripts/`, ...). Your code should ignore all them. I would like to ignore only directories, sub-directories and files in the `public/users/`. – Backo Sep 15 '11 at 06:58
  • In other posts that I mentioned in the question, people must run some git command, but those for me seem do not work. – Backo Sep 15 '11 at 07:00
  • have you already added those files to repo or is it not commited to repo ? – Gaurav Shah Sep 15 '11 at 07:01
  • I cannot put all user related files in a single directory. – Backo Sep 15 '11 at 07:01
  • If with "repo" you mean if I run the `git add .` command the answer is yes. – Backo Sep 15 '11 at 07:02
  • then just do a git delete to those files and then commit and then add it to gitignore – Gaurav Shah Sep 15 '11 at 07:07
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/3479/discussion-between-backo-and-gaurav-shah) – Backo Sep 15 '11 at 07:08
  • I am in the CASE 2, but I don't know how to use the "`git delete`" command. – Backo Sep 15 '11 at 07:12
  • Now, after performing all steps as you wrote, on the remote machine the `public/users` directory is removed\deleted. I need that since in that there are user related files. *How can I solve the issue so to have that directory on the remote machine without that Capistrano\git edit its contante anymore?* – Backo Sep 15 '11 at 07:40
  • The related chat is the main reason why I accepted this answer as the correct one. – Backo Sep 15 '11 at 09:33