-1

I have a new git repository in which I made 1 commit and made a push. I forgot to set up a git ignore and now a lot of garbage got into it. Now I set up a git ignore, but now how to remove all the garbage from the repository?

A1ex NS
  • 57
  • 9
  • What prevents you from removing the files? – Micha Wiedenmann Dec 12 '18 at 07:43
  • Manually delete every file from the repository? – A1ex NS Dec 12 '18 at 07:49
  • Use `git filter-branch` to remove these file from history, or simply delete them and make a commit (remains in history but not tracked in the future). – Geno Chen Dec 12 '18 at 07:52
  • Try some of the solutions outlined in this answer: https://stackoverflow.com/questions/1274057/how-to-make-git-forget-about-a-file-that-was-tracked-but-is-now-in-gitignore – BenKoshy Dec 12 '18 at 08:08
  • You might want to revert the inital commit, as described [here](https://stackoverflow.com/questions/6632191/how-to-revert-initial-git-commit), and commit again, this time with `.gitignore` in place. – kowsky Dec 12 '18 at 08:10

1 Answers1

0

In this particular case (repo init), just revert your last commit and then include an adapted .gitignore.

To revert your last commit and keep files staged :

  git reset --soft HEAD^1
Nicolas Voron
  • 2,916
  • 1
  • 21
  • 35