3

I have a single branch git repository, that has ~4000 commits. I want to group the commits according to dates they were created. For example, given the commits below:

abcd 2013-4-1 12:10
abce 2013-4-1 13:27
...
cdef 2013-4-1 18:16
cdeg 2013-4-2 09:23
...
gade 2013-4-2 18:20
fdeg 2013-4-3 09:42
... 

I would like to get a commit history such as all abcd-cdef commits merged into one commit, all cdeg-gade into one and so on. I tried to use rebase as

git reset --hard cdef
git rebase -i abcd

I couldn't manage to squash all the commits, got the folloving error message.

"Cannot 'squash' without a previous commit"

I tried to squash one commit at a time, it worked, but it took so long that it is clearly not feasable.

How can I merge the commits according to their creation dates?

1 Answer 1

5

Mark the first commit from each day as "reword" and the rest as "fixup":

reword xxxxxx First commit from 2013-04-01
squash xxxxxx another commit from 2013-04-01
squash xxxxxx another commit from 2013-04-01
reword xxxxxx First commit from 2013-04-02
etc

This will prompt you to write a new commit message for each day.

Note that doing commits on a time basis is almost always the wrong thing to do. For tools like git bisect to work correctly, each commit in a repository should represent a "bite-sized" change.

2
  • +1 because this answer points out that grouping commits by date is absolutely an incorrect thing to do. Commented Apr 16, 2013 at 2:31
  • @duskwuff thank you for the reply and warning. commits belong to an automated service that backs up incremental data, for the purpose of being able to trace the changes in data structure. Only the service itself updates and commits the data, one update at any given time. no other branches, collaboraters are involved. problem is, many commits sometimes cause the "git pull"s executed on other machines and "git gc"s in the repository itself die with insufficient memory errors. does this still make a bad option?
    – altunyurt
    Commented Apr 16, 2013 at 11:29

Not the answer you're looking for? Browse other questions tagged or ask your own question.