Creating a new directory in Heroku - django

I'm very new to Heroku and I've just pushed my Django app into Heroku. Does anyone know how to create a 'log' directory under '/app'? Is /app the top directory of my app?
Thanks

Is the log directory in your .gitignore file? If /log is an unversioned directory then K Z's answer should help regarding Heroku; unless something else is going on with Heroku and the log directory in your repo.
Regarding committing an empty directory
You cannot commit empty directories to git, but you can add a .gitignore file in a directory that ignores all files inside except itself. This would be as close as you can get to versioning an empty directory as I'm sure you don't want to version control your log files.
Make sure the log directory is not in your main .gitignore file. Then in your log directory create a new .gitignore that contains the following:
# Ignore everything in this directory
*
# Except this file
!.gitignore
You can check out Jamie Flournoy's answer here How can I add an empty directory to a Git repository?

To create a new directory you can simply create one in your local directory (i.e., cd app; mkdir log then commit & push to Heroku.
Whether /app is the top directory or not depends on your directory structure, normally it is the name of the app on Heroku that's set as the top directory. Though, if you are inside your git repository that's used for your Heroku app, you can find the root directory by:
git rev-parse --show-toplevel
which is a git command that tells you the top level directory of this git directory.

Related

Not able to ignore static files from getting pushed to git in Django project

I had pushed a new Django project BTRE to my git repository. But I can't ignore the static files from pushed to the repository even though I have mentioned the directories in .gitignore file.
-BTRE_Project
|-btre
|-static
This is my .gitignore file:
# If your build process includes running collectstatic, then you probably don't need or want to include staticfiles/
# in your Git repository. Update and uncomment the following line accordingly.
btre/static/
I have tried deleting the repository and pushing again after updating the .gitignore file.
if you want to ignore your static folder and all the files inside static folder than put this in your .gitignore file
static/
this will ignore static directory and files inside that
You can add ignore by adding the folder path in .gitignore file also use git lfs if you want to commit static files.

Push file create by Django than need to be ignore by git

I have make a first push to Gitlab with git, but the.gitignore wasn't completely configure.
I configure the .gitignore like this now :
# Environments
env/
# Byte-compiled / optimized / DLL files
poc_project/poc_project/__pycache__
poc_project/pollution/__pycache__
__pycache__/
*.py[cod]
*$py.class
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
The env/ and poc_project/poc_project/__pycache__ aren't push but the db.sqlite3 and poc_project/pollution/__pycache__ are already on the distant repository (Gitlab).
I use this https://github.com/github/gitignore/blob/master/Python.gitignore for configure my .gitignore because I use django. My teammate will soon start working on the project.
It's a problem to have pycache file and db.sqlite3 for team work on distant repository with Django?
If yes how can I delete these files correctly from gitlab repository ?
If they do not contain any sensitive information: just delete the files and commit the deletion. If they do contain sensitive information they would still be present in the history, even after you delete the files. That requires some additional work, see: Remove sensitive files and their commits from Git history

Ignoring file in Github and Django

Me and my friend are both working on a project in Django. We are beginners with both GitHub as well as Django. We have managed to use .gitignore to ingore certain files. This is how the .gitignore looks like :
.DS_Store
groupProject/__pycache__
marketplace/__pycache__
marketplace/migrations/__pycache__
marketplace/templatetags/__pycache__
db.sqlite3
The only issue that we have is that when we try to push we get an error saying that there is a merge conflict for this file 'db.sqlite3' . I have added this file in .gitignore and for some reason it still decides to read it?
What should we do?
Try to delete the db.sqlite from the repository with the command:
git rm --cached db.sqlite
I think this happened because yout ignored the db.sqlite after you added it to the repo ;)

Visual Studio adds git directory one directory too high

For a Django project, I want the git directory in the same directory as the manage.py file. When I create a new python web project in Visual Studio it creates the git directory one directory above where I would put the manage.py file. How do I put the git directory in the right place?
Let's say I create a new project in a folder called "project_dir". The .git directory is placed there. Visual studio creates a sub-folder with the project name (call it project_name) and only allows you to add files and folders within that sub-folder. I want the git data in project_name.
project_dir
├───.git
├───.gitignore
├───project_name.sln
├───project_name
│ ├───manage.py
│ └───project_name.pyproj
When I create a new project I do not have "create new directory for solution" checked. I seems like it's creating a directory for the solution file (.sln) anyway.
Alternative way is you can create the project using command line and run git init command in your project folder. This will initialize the git repo in your project folder.
At the same level with manage.py.

I have settings.py in my .gitignore yet it still changes it when I do git pull

I have a different settings.py for my local project and my live project (Bitbucket repo). So I have added settings.py to my .gitignore so when I make changes to either file, they don't get sent to the other repo when my git is pulled or pushed.
However, I just did a git pull from my local repo - and it did a merge and changed the settings.py file to the Bitbucket settings.py.
What is going on?
Edit - Gitignore file:
/lib
/media
.env
/include
/reports
.DS_Store
*.pyc
celerybeat-schedule.db
__pycache__/
db.sqlite3
log.django
settings.py
static/
/static
If there is a settings.py file already in your repo, adding it to .gitignore won't stop the file from being pulled. The only way to do that is to remove it completely from the repo.
But this is the wrong thing to do. You should not exclude the whole settings file from version control. Almost all of the settings will remain the same between dev and production; there are plenty of techniques for maintaining those that differ, from a separate local_settings file to using environment variables.
To make git stop tracking the settings.py completely including the previous commits.
git does not ignore a file that has already been tracked before a rule was added to .gitignore file to ignore it.
In such a case the file must be un-tracked first with this command: git rm --cached <filename>.
So if you are trying to ignore this file after the initial commit, run this: git rm --cached settings.py, and you should be good to go.
To make git stop tracking future changes in settings.py, apart from the initial commit.
Refer this answer.
I think you've already pushed the settings.py file to remote. So when you pull from remote. Your local file will also change even you've added this file to .gitignore. git will continue to track any files that are already being tracked.
A simple way to resolve this issue.
First:
git rm -r --cached .
git add .
and then:
git commit -am "Remove ignored files"
For more please refer this answer.
You can use git stash. It will keep you current settings.py as stash, then you can perform git pull. Then once pull is done, you can do git stash apply, this will restore all stashed files like settings.py and merge them is any thing is changed.