hugemeow
hugemeow

Reputation: 7985

how to merge two git commits into one?

i have made two commits while in fact one commit is enough, the reason that i make two commits is because i forget to add one file after i make the first commit, so i add it and make another commit, after that i found that i find i have made two commit with the same comment, so how to merge these two commits into one?

* 3e381e7 - (HEAD, master) now i have add load script which can open many pages automatically at one time (4 seconds ago) 
* 2d97025 - now i have add load script which can open many pages automatically at one time (21 seconds ago) 

how to merge commits 3e381e7 and 2d97025 so that there is only one commit log?

Upvotes: 1

Views: 4269

Answers (2)

mb14
mb14

Reputation: 22636

Interactive rebase is your friend :

git rebase -i

You can also do a git reset --soft followed by a git commit --amend but rebasing is the easiest way.

Upvotes: 3

moritz
moritz

Reputation: 12852

Joining two commits into one is called "squashing". Do an interactive rebase,

git rebase -i HEAD~3

and then in the text editor that opens, change the line with the 2d97025 to start with the word 'squash', then safe the file and exit the editor.

Upvotes: 2

Related Questions