Reputation: 1482
I'm pretty new to github. I uploaded one of my projects and accidentally I also committed all my binary files. I used the website of github to manage my project and to remove the binary files. The problem is that every time I removed a file it counted as a commit.
Normally this is no problem but I'm the kind of person who loves to look at statistics and see how they evolve.
Now the commit statistics and other statistics that relate to the commit count are messed up and look like the project is going downhill very quickly since the few hundred manually removed binary files all count as single commits vs. my 2-8 regular commits a day now.
Is there any nice way to bundle committed commits to a single commit or to remove them from the commit statistics at all?
I'm aware that I could just delete the project and re-upload it again but then I would lose the history of my files.
Upvotes: 0
Views: 683
Reputation: 459
There are many answers to this problem. One of them is
git rebase -i HEAD~n
// n will define the range of commits that you want to consider
// You can also use a SHA1 hash instead of HEAD~n
This interactive rebase will show you a list of commits. If you want to squash them all together, you simply prefix every commit (except the first one) with squash. This is explained in the interactive rebase instructions that will appear in your command line.
So if you set n=4 and you see this:
pick 111111 // Random hashes
pick 222222
pick 333333
pick 444444
Simply replace this by
pick 111111
squash 222222
squash 333333
squash 444444
This will result, in the end, in a single commit containing the code changes of these 4 commits. Note that this will rewrite the git commit history. Those 4 commits will dissapear and will be replaced with the new, aggregate commit.
While not the simplest solution, it does allow for more flexibility. Interactive rebasing also allows you to rename commit messages, reorder commits and more. It would also allow you more granularity if you wanted to, say, squash 2 commits into one commit, and squash 2 other commits into one commit. Example:
pick 111111
squash 222222
pick 333333
squash 444444
For more details https://www.atlassian.com/git/tutorials/rewriting-history/git-rebase-i/
Upvotes: 3