2017-09-26 92 views
0

我在本地win7机器上构建了一个web应用程序。我用pycharm做了它,并使用git作为版本控制。我是一个总Git新手。从pythonanywhere添加/提交时,将`__pycache__`保存在我的存储库中

我把存储库放在github上,这样我就可以将webapp放到我的pythonanywhere服务器上。

在pythonanywhere方面,我对各种文件做了一些小的编辑。我想将这些更改提交回存储库。

(udemy) 10:44 ~/keystone (master)$ git commit -m "got it running on pythonanywhere staging" 
On branch master 
Your branch is up-to-date with 'origin/master'. 
Changes not staged for commit: 
     modified: keystone/settings/base.py 
     modified: keystone/settings/local_postgres.py 
     modified: keystone/settings/staging_straits.py 
     deleted: p0150_1.pdf 
Untracked files: 
     crapboard/__pycache__/ 
     crapboard/migrations/__pycache__/ 
     crapboard/templatetags/__pycache__/ 
     keystone/__pycache__/ 
     keystone/settings/__pycache__/ 
no changes added to commit 

有三个修改的文件和一个我想提交到存储库的删除。

,所以我做

(udemy) 14:03 ~/keystone (master)$ git add --all 
(udemy) 14:03 ~/keystone (master)$ git commit -m "staged to pythonanywhere" 
[master ac6bb7e] staged to pythonanywhere 
27 files changed, 23 insertions(+), 115 deletions(-) 
create mode 100644 crapboard/__pycache__/__init__.cpython-36.pyc 
create mode 100644 crapboard/__pycache__/admin.cpython-36.pyc 
create mode 100644 crapboard/__pycache__/apps.cpython-36.pyc 
create mode 100644 crapboard/__pycache__/forms.cpython-36.pyc 
create mode 100644 crapboard/__pycache__/models.cpython-36.pyc 
create mode 100644 crapboard/__pycache__/pdf_views.cpython-36.pyc 
create mode 100644 crapboard/__pycache__/urls.cpython-36.pyc 
create mode 100644 crapboard/__pycache__/views.cpython-36.pyc 
create mode 100644 crapboard/migrations/__pycache__/0001_initial.cpython-36.pyc 
create mode 100644 crapboard/migrations/__pycache__/0001_squashed_0005_auto_20170921_2154.cpython-36.pyc 
create mode 100644 crapboard/migrations/__pycache__/0002_auto_20170909_1137.cpython-36.pyc 
create mode 100644 crapboard/migrations/__pycache__/0003_auto_20170912_2029.cpython-36.pyc 
create mode 100644 crapboard/migrations/__pycache__/0004_problem_author.cpython-36.pyc 
create mode 100644 crapboard/migrations/__pycache__/0005_auto_20170921_2154.cpython-36.pyc 
create mode 100644 crapboard/migrations/__pycache__/__init__.cpython-36.pyc 
create mode 100644 crapboard/templatetags/__pycache__/__init__.cpython-36.pyc 
create mode 100644 crapboard/templatetags/__pycache__/crapboard_filters.cpython-36.pyc 
create mode 100644 keystone/__pycache__/__init__.cpython-36.pyc 
create mode 100644 keystone/__pycache__/urls.cpython-36.pyc 
create mode 100644 keystone/settings/__pycache__/__init__.cpython-36.pyc 
create mode 100644 keystone/settings/__pycache__/base.cpython-36.pyc 
create mode 100644 keystone/settings/__pycache__/settings_secret.cpython-36.pyc 
create mode 100644 keystone/settings/__pycache__/staging_straits.cpython-36.pyc 
rewrite keystone/settings/staging_straits.py (65%) 
delete mode 100644 p0150_1.pdf 

哎呀。它也承诺所有这些__pycache__目录。

我猜这发生是因为我应该在我的pythonanywhere服务器上创建某种全局/通用.gitignore文件?

所以问题:

1)我如何才能从我的仓库摆脱这种pycache东西永久 2)我如何防止我的pythonanywhere服务器试图这些东西添加到我的仓库在未来 - 我没有pycharm /本地机器的问题 - 它忽略了这些文件。

+1

一些线索:https://stackoverflow.com/questions/1139762/ignore-files-that-have-already-been-committed-to-a-git-repository(你可能已经有一个.gitignore文件在你的目录中的某处) – doctorlove

+0

关于第(1)部分:请注意,你不能*改变*任何现有的提交,但是你可以停止使用它们,并且最终,如果没有办法找到它们,它们就会过期。如果你没有*发送*这个新的提交任何其他地方(所以只有你有它),你可以停止使用此提交(通过使用'git commit --amend'推到一边,或'git reset'来隐藏它离开以至于即使你看不到它)。那么你不会在你的(可见的)任何提交中拥有'__pycache__',这样你就不会发送提交给任何其他仓库的提交。 – torek

+0

把它放在.gitignore中 –

回答

1
  1. 你可以做一个git rm删除该文件夹,然后提交并推送。或者如果你感觉超级冒险,而没有其他人使用你的回购,你可以做一个commit --fixup,然后rebase --interactive清理所有东西。详情请参阅here
  2. add __pyacache__ to ~/.gitignore。或者更好的办法就是检查.gitignore文件以获取回购。
相关问题