Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I merge two commits in git?

Tags:

git

git-stash

I recently pushed a commit to my git remote repository, and now I'm going to commit another change.

Is there a way I can merge these commits into a single commit?

like image 928
Tumuluri V Datta Vamshi Avatar asked Nov 20 '25 21:11

Tumuluri V Datta Vamshi


1 Answers

You can do this using interactive rebasing.

Run the following:

git rebase -i HEAD~2

You'll see something like this, in the editor that opens:

pick 3e7ee36 Older commit message
pick fa20af3 Newer commit message

# Rebase 8db7e8b..fa20af3 onto 8db7e8b
# ...

fixup or squash the newer commit, i.e., replace the pick in the newer commit to fixup and save and quit the file. This will merge the 2 commits keeping the older message:

pick 3e7ee36 Older commit message
fixup fa20af3 Newer commit message

# Rebase 8db7e8b..fa20af3 onto 8db7e8b
# ...
like image 53
John Bupit Avatar answered Nov 23 '25 12:11

John Bupit



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!