Remove .pyc files from Git remote repository

2019-03-08 13:18发布

Accidentally, I have pushed the .pyc files to the master repository. Now I want to delete them but I can´t do it. Is there any way to remove them directly from the Bitbucket site?

标签: git pyc
10条回答
劫难
2楼-- · 2019-03-08 13:35

I used simeg's solution but also wanted to deleted tons of *.pyc files added by mistake to a branch. I used awk to delete them from cache recursively.

git status | awk '{if($1=="modified:" && $2!=".gitignore") ; system("git rm --cached "$2)}'

Then, I deleted the files from my local

find . -name *.pyc -delete
查看更多
我命由我不由天
3楼-- · 2019-03-08 13:40

Because in default Bitbucket, there is no .gitignore file in the repo,so you can do :

  1. you can create local .gitignore(should not be pushed) and add *.pyc as a line;
  2. you can copy the .gitignore in Github repo and add *.pyc as a line in this file! You can push it or keep it in your local repo!
查看更多
神经病院院长
4楼-- · 2019-03-08 13:40

Quick way with PyDev for eclipse.

Go to the PyDev Package Explorer of your project and do:


  • right click + Pydev / Remove *.pyc *.pyo and *$py.class File

    a window will popup telling you how many files have been deleted.

Optional: Commit your change to the team/server:

  • right click + team / commit

In the commit window you shouldn't see any .pyc available to add as we deleted them. Also if you committed such files before then you should be able to commit their "deletion" now.

===> Your local and server repository are now free of *.pyc *.pyo and *$py.class File :)

查看更多
甜甜的少女心
5楼-- · 2019-03-08 13:43
  1. Remove .pyc files using git rm *.pyc. If this not work use git rm -f *.pyc
  2. Commit git commit -a -m 'all pyc files removed'
  3. Push git push
  4. In future commits you can ignore .pyc files by creating a .gitignore file
查看更多
老娘就宠你
6楼-- · 2019-03-08 13:44

A one-liner for fun:

git status | grep pyc | sed -e 's/ new file: //g' | xargs -I {} git rm --cached {}

查看更多
SAY GOODBYE
7楼-- · 2019-03-08 13:47

another liner for fun to remove all the pyc files.

find . -name '*.pyc' -exec git rm {} \;

don't forget to follow the steps in other answers to commit and add gitignore.

查看更多
登录 后发表回答