Git is ignoring gitignore file under Windows 10 - python

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

Related

Python setup.cfg: how to add package_data with git submodules?

I'm writing a Python package, in which I'm adding package data. The package data of my setup.cfg looks like the following:
include_package_data = True
[options.package_data]
mypymodule = dir1/*/*, dir2/*/*
Both dir1 and dir2 are directories inside mypymodule source folder, which is part of "mypackage". Building, installing and using "mypackage" is not an issue.
The trouble I'm facing is the following:
Both dir1 and dir2 have their subdirectories with some files inside each that I want to include in "mypackage" installation, and then access them as resources when "mypackage" is running.
For dir1, everything is fine: all dir1 subfolders are correctly installed within "mypackage".
But for dir2, it looks like the installation is not recursive: only files belonging directly at the dir2 folder are installed within "mypackage"; all dir2 subfolders are ignored in "mypackage" installation, and I am not able to access their content as resources.
The difference between dir1 and dir2 is:
dir1 is a regular directory in "mypackage" git repo
dir2 is added in "mypackage" git repo as a git submodule
What am I missing? Is there some limitations in adding git submodules are package_data in Python packages setup.cfg?
Hope you can help! Thank you!
I've tried changing the "*" notation for subdirectories in setup.cfg file, but with no success. I expect that both dir1 and dir2 are treated evenly whether regular dirs or git submodule dirs.
The issue is the sub dir notation I used; there is nothing to with one of the dirs being a git repo or not. I just mistaken the sub dir level I wanted to include.
For including recursiely anything below a dir, double star notation ** is needed. Backslashs plus stars /*/* only adds until the denoted level.
The correct notation in my example is:
include_package_data = True
[options.package_data]
mypymodule = dir1/**, dir2/**

How do you create a gitignore file in pycharm? (windows)

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.

git ignore not ignoring a file when using GCloud's gcloudignore

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.

How to add all catalog using GIT without .pyc file?

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

Ignore .pyc files in git repository

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).

Categories