2017-09-26 89 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文件以獲取回購。
相關問題