-1

I committed several file changes without adding some files to .gitignore that I didn't want to include.

I added those files to .gitigonre (.npy and few .png)file and committed but files didn't remove.

How can I remove these files from all commits? if not possible from all commits I'm happy to a new fresh but a clean commit.

My repository screenshot

phd
  • 82,685
  • 13
  • 120
  • 165
Haseeb Ayub
  • 25
  • 3
  • 10
  • 1
    Delete them, add the change, then commit. You can do the first two steps with `git rm filename`, but you will have to commit the delete. The files will be left in the commits you already have, but will be deleted going forward. If they reappear on disk after you have committed the delete, for instance if they're build output, as long as you've added them to gitignore they should not be readded. If you want to get rid of them also from existing commits, you need to do something else. – Lasse V. Karlsen May 08 '20 at 11:39
  • https://stackoverflow.com/questions/61212/how-to-remove-local-untracked-files-from-the-current-git-working-tree – matt May 08 '20 at 11:46
  • @LasseV.Karlsen Thank you, worked! but I had to made multiple commits. – Haseeb Ayub May 09 '20 at 09:22

1 Answers1

0

If you are fine removing commit history then simply delete those files which you didn't wanted to include and make another commit.

Once done, rebase all commits (Avoid this step if you don't want to clear commit history).

Add those files to .gitignore to avoid pushing them again.

Steps you should follow for adding files to .gitignore

1) Add files which you don't want to commit in .gitignore file

2) Commit .gitignore file and push the changes

Next time, you won't see any of those file while making a new commit.

Let me know if you still face the issue!

Milind Agrawal
  • 2,724
  • 1
  • 13
  • 20