0

I've accidentally committed 2k+ files from my node_modules directory. I've added node_modules/ to my .gitignore file as well as called git rm -r node_modules/.

I still see that I've changed 2.xk files on GitHub in my PR. What's the resolution to this mistake?

Ryan Shocker
  • 693
  • 1
  • 7
  • 22

3 Answers3

0

You can just revert you latest commit with previous commit id. So your head will be currently pointing to the previous commit.

Sudharsan Selvaraj
  • 4,792
  • 3
  • 14
  • 22
0

Use git rebase -i <last okay commit>, then amend the commit(s) that add the wrong files.

o11c
  • 15,265
  • 4
  • 50
  • 75
0

Assuming that in your latest commit you removed unwanted files and pushed that into github and that commit before is the one where you committed files that you do not want and your current state is satisfactory to you then you should be able to do something like this

git reset --soft HEAD~3
git commit
git push -f origin master

Where HEAD~3 refers to commit right before the one where you introduced bunch of unwanted files. The procedure described above essentially squashes you last two commits into one, but please be careful with git push -f as this will override whatever it is that you have in github.

Dmitri
  • 114
  • 5