Reputation: 2207
When I first created my repository many months ago, I was an amateur and committed the files of the libraries I was using into source control because apparently I hadn't learned about .gitignore yet. I eventually realized my mistake, added the line to .gitignore and removed the libraries from the repo.
Everything is fine now, but the Github code frequency graph is now useless because the Y-axis scale is so high due to the amount of code that was checked into the repo that one time.
Is there any way I can essentially remove those commits from Git without affecting the current state of the repo? Or any way that I can tell Github to ignore those commits in the graphs?
Upvotes: 5
Views: 3125
Reputation: 17292
Because you've already pushed those commits to Github, they are public commits and it is generally not recommended to amend them. With that being said, if you are currently the only person who is contributing to this repository, it is an option. I'll leave it up to you to decide if it is a good option.
You can amend whichever commit added those files (using git commit --amend
, probably with git rebase -i
). You'll have to push that as described here: How do I push amended commit to the remote Git repository?.
Alternatively (depending how old this project is), just start over. Run git init
and make a good initial commit.
Upvotes: 2
Reputation: 440
Depending on how mixed up the commits are, you might solve it quickly and neatly. If you commited other changes with that commit you are going to need to do some more work and edit the commits instead of removing them.
git rebase -i fffffaaaaa~1
where fffffaaaaa is your commit and then remove the row with "pick fffffaaaaa ..." then handle rebase as usual.
After you've removed them locally and verified you didn't break anything you could force push your new history.
REALLY consider if it is worth it carefully though if you share the repo with others, since stuff is gonna get weird for them if you push your new history.
Upvotes: 0