Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I squash and edit the same commit?

When I do an interactive rebase in git, how do I squash a commit and also stop end edit the same commit?

like image 829
cambunctious Avatar asked Oct 28 '16 20:10

cambunctious


People also ask

How do you modify an existing commit?

Changing the Last Commit: git commit --amend. The git commit --amend command is a convenient way to modify the most recent commit. It lets you combine staged changes with the previous commit instead of creating an entirely new commit.

Is it possible to go back and edit a commit message?

If you need to amend the message for multiple commits or an older commit, you can use interactive rebase, then force push to change the commit history. On the command line, navigate to the repository that contains the commit you want to amend.

What command would you use to squash a commit?

We'll address two different approaches to squashing commits: Interactive rebase: git rebase -i … Merge with the –squash option: git merge –squash.


2 Answers

Do it in two steps, first squash and next in second run of interactive rebase edit squashed commit.

like image 76
Slawomir Jaranowski Avatar answered Sep 29 '22 14:09

Slawomir Jaranowski


Alternatively, you could use 'edit' to edit the commit, and then do e.g.

git reset --soft HEAD^
git commit --amend
like image 29
ObsequiousNewt Avatar answered Sep 29 '22 13:09

ObsequiousNewt