Jusleong
Jusleong

Reputation: 571

How to delete a sub commit after squashing commits?

As far as I know, git squash is quite useful when there is a bunch of commits in one pull request. It can help to combine commits and then reduce the number of commits.

For example, here is what some squashed commits look like on GitHub:

edit readme once                        28d8d9c289665039e62d0be0f24876f096e591e2
  second edit

It looks like the sub commit second edit does not have a corresponding ref.

Is it possible to just remove the sub commit like second edit after squashing commits?

Upvotes: 1

Views: 380

Answers (1)

Nicky McCurdy
Nicky McCurdy

Reputation: 19564

Short answer

Use fixup instead of squash. It's like squash, but it will discard the commit messages for everything but the first commit.

Long answer

It seems to me that this isn't a "subcommit", but instead someone accidentally kept the commit message of the second commit in the new squashed commit. By default, a squash will combine both commit messages, and it's up to you to update the message.

In this case, there is nothing you would need to remove. Just remember to change commit message as appropriate the next time you squash. You can also use fixup when you don't need the other message.

Upvotes: 1

Related Questions