Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove .pyc files from Git remote repository

Tags:

git

pyc

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?

like image 907
ePascoal Avatar asked Sep 24 '14 15:09

ePascoal


People also ask

How do I remove a .gitignore file?

gitignore are not being tracked, you can use the git clean command to recursively remove files that are not under version control. Use git clean -xdn to perform a dry run and see what will be removed. Then use git clean -xdf to execute it. Basically, git clean -h or man git-clean (in unix) will give you help.

How do I remove a file from a git command?

The git rm command can be used to remove individual files or a collection of files. The primary function of git rm is to remove tracked files from the Git index. Additionally, git rm can be used to remove files from both the staging index and the working directory.


2 Answers

  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
like image 51
Falcoa Avatar answered Sep 30 '22 07:09

Falcoa


No, you cannot delete them directly from the BitBucket interface but you can delete them in your local checkout and find ./ -type f -name '*.pyc' -exec git rm {} \; ( or simply git rm each pyc file one by one ). Then commit/push your changes.

Finally, to avoid ever making the same mistake again you may create a file at the root of your repo and name it '.gitignore' with the contents:

*.pyc *~ *.swp 

*~ and ~.swp are other commonly forgotten file types that are often accidentally pushed. See the github doc on gitignore https://help.github.com/articles/ignoring-files (and their repo of .gitignore files for some nice defaults).

like image 34
smassey Avatar answered Sep 30 '22 08:09

smassey