rkmax
rkmax

Reputation: 18133

Combine old log entries from git log

I have a project with the following log

commit10
commit09
commit08
commit07
commit06
commit05
...
commit01

I want convert commits from 01 to 08 to only one commit. the result I want is

commit10
commit09
commitXX

where the commit message is something like 'initial commit' or something. How I can achieve this?

Upvotes: 2

Views: 31

Answers (1)

DilithiumMatrix
DilithiumMatrix

Reputation: 18637

Use the git rebase command, or interactively (which is nice) as git rebase -i. In particular, this would be a 'squash' --- to combine some commits into others.

Here, the best way to do this might be: git rebase -i HEAD~10 to look at the 10 most recent commits. You can then use the interactive prompt to select which ones to 's'quash and which to 'p'ick (i.e. preserve).

In your case this might look like:

p SHA10 commit10
p SHA09 commit09
s SHA08 commit08
s SHA10 commit07
...
s SHA01 commit01

Then it will prompt you to change the commit message - if you want to.

If you want to undo your rebase, use git reset --hard ORIG_HEAD --- rebase saves the previous state to ORIG_HEAD.

Upvotes: 1

Related Questions