2

I'm having a very strange issue and I wish to know your advice on this please.

Sometimes, when I push changes to REMOTE server, the changes don't appear. I do ssh to the remote machine, I do a git status, and I see:

modified: app/runtime/application.log

The thing is, all directory, and now also, specific files there, are being targeted by .gitignore .

/nbproject/
/app/runtime/
/public_html/assets/
/app/runtime/application.log*
/app/runtime/error.log*

No ftp as being done directly, only push and pull has been used.

Maybe they are things written to app/runtime/application.log on the live site, so the application.log is different from the one in the repository, and when that happens git refuses to pull, because it will then overwrite application.log to an older version.

This may happen to a number of other files on that same directory. Files that could be created by the live site, the moment the application runs.

My question is, how can we avoid this? Why .gitignore seems to NOT be effective here?

ps - If I need to provide some more details, like server hooks or something, please let me know.

MEM
  • 30,529
  • 42
  • 121
  • 191

2 Answers2

9

Sounds like you added app/runtime/application.log to git before applying the .gitignore rules. gitignore doesn't affect git's awareness of existing files, only newly created ones.

git rm --cached app/runtime/* should remove the logs from git's index.

Community
  • 1
  • 1
DCoder
  • 12,962
  • 4
  • 40
  • 62
  • Should we do this on both, local and remote repos? – MEM May 27 '12 at 10:39
  • 1
    @MEM: I'm assuming it's tracked in both repos? Then you should remove it from local, push the commit, and try to pull to remote. If that fails (it probably will), remove it from the remote as well, and pull/merge again - git should merge the changes without further problems, since they'll be identical on both sides. – DCoder May 27 '12 at 10:47
  • One last question: I've done this on my machine, and all seems to be working fine. Pushing and Pulling no issues. Other programmers that have also pushed and pulled on this project, need to do this on their local machines as well ? Or, since it's already taking care of, no need to do nothing, because git will not take this into consideration anymore ? Thanks again. – MEM May 27 '12 at 11:49
  • 1
    @MEM: they would only need to do this locally if pulling fails. – DCoder May 27 '12 at 11:50
  • Thanks a lot for your time and patience towards this. – MEM May 27 '12 at 11:54
2

From man gitignore:

A gitignore file specifies intentionally untracked files that git should ignore. Files already tracked by git are not affected.

So, if your application.log file is added to the repository, then gitignore will do nothing.

The solution would be to remove these files from the repository. Do you really need to synchronize the log files?

git rm --cached app/runtime/application.log

And so on.

rodrigo
  • 94,151
  • 12
  • 143
  • 190