0

I just noticed that the project the junior developers in my company are working on have not added node_modules to .gitignore file at the beginning of the project... Now I was taking a look at the commit history and I noticed that the git pull took a lot of time and there were a lot of changes, so the reason was that they did not ignore node_modules directory .

All I want to do is re-write the commit history and git push --force and tell them to git pull --rebase.

Is there any way to re-write that history without that node_modules folder?

A Master in Git is needed here!

Alan Deep
  • 2,037
  • 1
  • 14
  • 22
  • 2
    Does this answer your question? [Remove folder and its contents from git/GitHub's history](https://stackoverflow.com/questions/10067848/remove-folder-and-its-contents-from-git-githubs-history) – mkrieger1 Oct 14 '20 at 19:49
  • 1
    Why rewrite history? Just remove the folder from staging and commit now. See https://stackoverflow.com/questions/50675829/remove-node-modules-from-git-in-vscode – matt Oct 14 '20 at 19:49
  • 3
    Or a master of search engines. – mkrieger1 Oct 14 '20 at 19:49
  • @matt you're right, but let's say I'd like to compare several commits from the past, why should I see useless changes? right? – Alan Deep Oct 14 '20 at 20:31

1 Answers1

0

You can rewrite the history using git filter-repo. This is one of its basic operations, so refer to the docs at https://htmlpreview.github.io/?https://github.com/newren/git-filter-repo/blob/docs/html/git-filter-repo.html

(You also could do this with git filter-branch, but the filter-branch command itself recommends against using it any longer.)

Mark Adelsberger
  • 42,148
  • 4
  • 35
  • 52