0

I've created a new repository in GitHub, but unfortunately I sent the first commit with node_modules In the second one I removed the node_modules and sent the .gitignore file that avoids to commit all the node_modules since that second commit.

After several more commits in the progress, I've found out that the repository size was big because that initial commit that had all the node_modules.

So, my question is: how can I delete that first commit from the log history to reduce the repository size?

Note: I don't care about the first commit history progress because I have much more progress in the subsequents commits

Leonardo Uribe
  • 123
  • 1
  • 13
  • 1
    Possible duplicate of [How can I remove a commit on GitHub?](https://stackoverflow.com/questions/448919/how-can-i-remove-a-commit-on-github) – jmargolisvt Jan 21 '19 at 14:28
  • 2
    Possible duplicate of [Edit the root commit in Git?](https://stackoverflow.com/questions/2119480/edit-the-root-commit-in-git) – kowsky Jan 21 '19 at 14:37

3 Answers3

2

You should use git rebase -i --root and squash the commit removing the node_modules folder with the first commit.

Philippe
  • 28,207
  • 6
  • 54
  • 78
  • This is a correct answer. To Leonardo: pay close attention to the fact you do not actually want to _delete_ your root commit; you instead want its changes to be integrated with the next one — precisely as explained here. – kostix Jan 21 '19 at 15:25
0

Git uses a tree organization that is only allowed to be added new nodes (commits). If you really want to delete a wrongly pushed commit you must update your repository locally and than force push to the according remote. I found an issue talking about it.

How to undo the initial commit on a remote repository in git?

-2

use git revert <commit_id_to_be_reverted>

Shrirang
  • 198
  • 1
  • 10