How to add all catalog using GIT witout .pyc file?
git add catalog_name
git commit -m "Update"
git push
What add and where?
use .gitignore file. add '*.pyc' to it.
The file is located in root directory of your repo i.e. where you did git init
Here is a good .gitignore file for python projects, containing common extension to ignore in git commit.
https://github.com/github/gitignore/blob/master/Python.gitignore
Related
Git is ignoring the folders in .gitignore file.
Here is my .gitignore : (env is a folder generated by venv in Python )
#folders
env/**
pdfs/**
# files
#source files
/timeformat.py
/pdfreader.py
I already did : git rm -r --cached . then git add . but it's adding all the files under env/Lib/site-packages
What is the problem ?
EDIT :
here is my directory structure :
Change your gitignore from
#folders
env/**
pdfs/**
to:
#folders
env/*
pdfs/*
The reason may be the .gitignore file and env folder not present at same level in directory structure.
You can start with **/dir to ignore the dir folder inside any directory.
In your case:
**/env/
change env/** to env /*
It did the job for me
What i could find relating to git settings on pycharm
In the Project tool window, select one or more files you wish to be ignored, then right click on the selection, then Git > Add to .gitignore > Add to .gitignore. If the .gitignore file does not exist, you will be asked for confirmation to create it.
First install the ignore plugin:
Then right-click the project root directory: New > .ignore File > .gitignore
If you want to simply create a .gitignore file in PyCharm, go to the PyCharm terminal and type: echo "" > .gitignore. Then open the .gitignore file, delete the double quotes, and update however you'd like.
Create a file with name .gitignore in the root directory of your project. Add all the files which you want git to ignore while versioning, in it.
I have a rule to ignore secret.py (production.py in my case) and once I added .gcloudignore, github stopped following that rule...
Is there some sort of a rule overriding between gitignore and gcloudignore that I am not aware of?
my-project/
.git
.gitignore
my-project/
.gcloudignore
settings/
base.py
local.py
production.py
my .gitignore:
my-project/my-project/settings/production.py
my-project/my-project/settings/local.py
my .gcloudignore:
# This file specifies files that are *not* uploaded to Google Cloud Platform
# using gcloud. It follows the same syntax as .gitignore, with the addition of
# "#!include" directives (which insert the entries of the given .gitignore-style
# file at that point).
#
# For more information, run:
# $ gcloud topic gcloudignore
#
.gcloudignore
# If you would like to upload your .git directory, .gitignore file or files
# from your .gitignore file, remove the corresponding line
# below:
.git
.gitignore
*.sqlite3
settings/local.py
End result is that the 'local.py' is NOT pushed to google cloud NOR github.
However, 'production.py' IS pushed to github AND gcloud.
If you had previously (perhaps accidentally) submitted a change to git that included my-project/my-project/settings/production.py, then it will remain a part of the repository even if it is subsequently added to .gitignore.
Assuming you are at the root of your project, you can use
$ git log my-project/my-project/settings/production.py
to see its git history. If it is present in your repo, you can do
$ git rm --cached my-project/my-project/settings/production.py
to remove it from the repo, but keep it in your local (working) environment.
Looks like you are enforcing to ignore the rules applied before.
Though make sure that the cloudignore is enable via
gcloud config set gcloudignore/enabled true
And make sure to place .gcloudignore - > in the root of your project / basically where you .git .gitignore reside.
gcloud app deploy keeps uploading all files in source directory, although I have explicitly excluded them using a .gcloudignore file. For example, the virtual environment folder env is uploaded, which is causing an error because the deployment contains more then 10,000 files then.
I am working under Windows 10 with Python 3.7 and gcloud SDK version 251.0.0. I tried both the beta and the normal version of gcloud app deploy.
The .gcloudignore file contains just the following:
.gcloudignore
# If you would like to upload your .git directory, .gitignore file or
# files from your .gitignore file, remove the corresponding line below:
.git
.gitignore
#!include:.gitignore
I can see in the outputs with --verbosity=info flag that it recognized the .gcloudignore file, but then it uploads the env folder to Cloud Storage. I would expect this folder to be skipped. Git works as expected.
You can "include" everything ignored by your .gitignore file in your .gcloudignore file by adding the following line:
#!include:.gitignore
If your .gitignore file is already ignoring the env directory, this will cause gcloud to ignore it as well (and every other file that git is ignoring).
Your .gcloudignore file contains two leading spaces on each line which are not allowed.
These spaces are copied from the documentation so many people will be facing this issue.
See the documentation here (but do not blindly copy from their until they fixed it)
How can I ignore .pyc files in git?
If I put it in .gitignore it doesn't work. I need them to be untracked and not checked for commits.
You should add a line with:
*.pyc
to the .gitignore file in the root folder of your git repository tree right after repository initialization.
As ralphtheninja said, if you forgot to to do it beforehand, if you just add the line to the .gitignore file, all previously committed .pyc files will still be tracked, so you'll need to remove them from the repository.
If you are on a Linux system (or "parents&sons" like a MacOSX), you can quickly do it with just this one line command that you need to execute from the root of the repository:
find . -name "*.pyc" -exec git rm -f "{}" \;
This just means:
starting from the directory i'm currently in, find all files whose
name ends with extension .pyc, and pass file name to the command git rm -f
After *.pyc files deletion from git as tracked files, commit this change to the repository, and then you can finally add the *.pyc line to the .gitignore file.
(adapted from http://yuji.wordpress.com/2010/10/29/git-remove-all-pyc/)
You have probably added them to the repository before putting *.pyc in .gitignore.
First remove them from the repository.
Put it in .gitignore. But from the gitignore(5) man page:
· If the pattern does not contain a slash /, git treats it as a shell
glob pattern and checks for a match against the pathname relative
to the location of the .gitignore file (relative to the toplevel of
the work tree if not from a .gitignore file).
· Otherwise, git treats the pattern as a shell glob suitable for
consumption by fnmatch(3) with the FNM_PATHNAME flag: wildcards in
the pattern will not match a / in the pathname. For example,
"Documentation/*.html" matches "Documentation/git.html" but not
"Documentation/ppc/ppc.html" or
"tools/perf/Documentation/perf.html".
So, either specify the full path to the appropriate *.pyc entry, or put it in a .gitignore file in any of the directories leading from the repository root (inclusive).
i try to use the sentence of a prior post and don't work recursively, then read some help and get this line:
find . -name "*.pyc" -exec git rm -f "{}" \;
p.d. is necessary to add *.pyc in .gitignore file to maintain git clean
echo "*.pyc" >> .gitignore
Enjoy.
If you want to ignore '.pyc' files globally (i.e. if you do not want to add the line to .gitignore file in every git directory), try the following:
$ cat ~/.gitconfig
[core]
excludesFile = ~/.gitignore
$ cat ~/.gitignore
**/*.pyc
[Reference]
https://git-scm.com/docs/gitignore
Patterns which a user wants Git to ignore in all situations (e.g., backup or temporary files generated by the user’s editor of choice) generally go into a file specified by core.excludesFile in the user’s ~/.gitconfig.
A leading "**" followed by a slash means match in all directories. For example, "**/foo" matches file or directory "foo" anywhere, the same as pattern "foo". "**/foo/bar" matches file or directory "bar" anywhere that is directly under directory "foo".
if you have committed in the repo, just
go to the folder /__pycache__,
delete all of them (no worries, they are temporary files and generated repeatedly)
have a new commit, such as 'update gitignore'
you are done! .pyc will not appear again.
Thanks #Enrico for the answer.
Note if you're using virtualenv you will have several more .pyc files within the directory you're currently in, which will be captured by his find command.
For example:
./app.pyc
./lib/python2.7/_weakrefset.pyc
./lib/python2.7/abc.pyc
./lib/python2.7/codecs.pyc
./lib/python2.7/copy_reg.pyc
./lib/python2.7/site-packages/alembic/__init__.pyc
./lib/python2.7/site-packages/alembic/autogenerate/__init__.pyc
./lib/python2.7/site-packages/alembic/autogenerate/api.pyc
I suppose it's harmless to remove all the files, but if you only want to remove the .pyc files in your main directory, then just do
find "*.pyc" -exec git rm -f "{}" \;
This will remove just the app.pyc file from the git repository.
Zachary's answer is correct. The reason that it's likely correct in your case is that gitignore will not work for files that preexist the gitignore (or the repository).