0

I created a Python venv in a folder. I installed some modules with "git install -t venv/Lib/site-packages module_name" I want to push my project without modules. I've written the name of the venv folder into .gitignore file. When I want to push my project, git tries to push everything. There some three files at .git/objects/pack/. They are 200mb. I don't have much git experience, so I can't find the problem.

(.venv) C:PATH>git add .                       

(.venv) C:PATH>git commit -m "test" 
[master b2cd8673] test
 1 file changed, 3 insertions(+), 1 deletion(-)

(.venv) C:PATH>git push origin master          
Enumerating objects: 38641, done.
Counting objects: 100% (38641/38641), done.
Delta compression using up to 8 threads
Compressing objects: 100% (13991/13991), done.
Writing objects:   0% (301/38637), 20.06 MiB | 1.90 MiB/s 

My .gitignore file:

.venv/
.venv
/.venv/

*.py[cod]

bfg-1.14.0.jar

I deleted .venv folder. And I get this message:

Enumerating objects: 38632, done.
Counting objects: 100% (31/31), done.
Writing objects: 100% (38632/38632), 186.75 MiB | 1.70 MiB/s, done.
Total 38632 (delta 31), reused 31 (delta 31), pack-reused 38601
remote: Resolving deltas: 100% (24536/24536), completed with 24 local objects.
remote: error: Trace: 413e6707cb9694673826a1a8ad802cd17bb02f4a5a691fd35fa5a668031381f8
remote: error: See https://gh.io/lfs for more information.
remote: error: File .venv/Lib/site-packages/catboost/_catboost.pyd is 341.50 MB; this exceeds GitHub's file size limit of 100.00 MB
remote: error: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.
To https://github.com/kdrcnuzmcu/python-alistirmalar.git
 ! [remote rejected]     master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://github.com/kdrcnuzmcu/python-alistirmalar.git'

I tried to fix it with BFG Repo Cleaner, it seemed like okay but nothing changed.

1 Answers1

0

So I did the following

mkdir git_test && cd git_test
git init
python3 -m venv .venv
source .venv/bin/activate
pip3 install -t .venv/lib/python3.8/site-packages/ numpy
echo .venv/ > .gitignore
git add .
git status # and only get "new file:   .gitignore"
git commit -m test

This create the git_test folders makes it a git repo. I created and activated a virtual environment, installed numpy into it, created a .gitignore and did the git add. It seems like this behaves like you want. I did not add the virtual environment only the .gitignore itself.

Are you sure your .gitignore is on the correct directory? It has to be in the root of the project that .venv/ will work in the gitignore.

I would try to get a clear version of the repo again, if you already added the files at one point it might be hard to get them out again. You want to reset to some commit where the whole .venv did not exist.

Always use git status to check what your current state is, especially after you did an add command, to make sure you really only add what you want to add.

Nopileos
  • 1,976
  • 7
  • 17
  • git doesn't try to push venv anymore. I mean, after to install the modules, the files at .git/objects/pack got huge. So I can't push them and get small – Kadir Can Üzümcü Jun 14 '23 at 14:29
  • But did you push them at any point. Once you committed and pushed them, they are in the history and will stay there, deleting them won't fix anything, it might make it worse actually, with how git tracks changes. If you committed them in the past you need to hard reset and force push to get rid of them https://stackoverflow.com/questions/3293531/how-to-permanently-remove-few-commits-from-remote-branch – Nopileos Jun 14 '23 at 18:13