Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compressing many commits into fewer, but larger, commits

Tags:

git

I git-commit everything I do every hour. This is nice but I end up with way too many commits.

I'd like to be able to purge this so that instead of :

1 hour ago
2 hours ago
.
23 hours ago
24 hours ago

I just have something like:

1 hour ago
2 hours ago
1 day ago
7 days ago

etc.

Currently each hour I do:

git-add .
git-commit -a

How can I remove certain commits? I don't want to undo any changes. I just don't care to have quite so many points to revert to. I'd like to have a lot of commits for the past few hours but then only a few after that (the past day, week, month, etc. or other major points that I keep on purpose).

like image 706
James Avatar asked Jun 02 '11 17:06

James


People also ask

Are smaller commits better?

Many Small CommitsThey are easier to understand, easier to test, and easier to review. The complexity of understanding, testing and reviewing a change often increases faster than its size: ten 200-line changes each doing one thing are often far easier to understand than one 2,000 line change doing ten things.

Should git commits be large or small?

Revert a commit with ease if something goes wrong. Big commits are harder to revert since you may not want to revert all of the changes but only a subset. Small commits are easier to understand when reviewing a pull request.

Should commits be squashed?

As a general rule, when merging a pull request from a feature branch with a messy commit history, you should squash your commits. There are exceptions, but in most cases, squashing results in a cleaner Git history that's easier for the team to read.


1 Answers

Have a look at the git rebase -i command. This lets you 'squash' commits into larger ones, which seems like what you want to do.

like image 58
Abizern Avatar answered Sep 23 '22 02:09

Abizern