(Git_6) Historical Commits — Insert, Reorder, Delete; Label

Insert commits

Given following commits

we are going to insert a commit between 62a13e6 and 1571341

use rebase

$ git rebase -i 44e1d7b

Change the head to the previous commit, so we need to edit the first commit

Now the HEAD is on the first commit

Then let’s do some changes

There is another file, insert.html, created. Then add and commit it

Then continue it

$ git rebase --continue

Then the insertion success

Reorder Commits

Given the commits

$ git rebase -i 44e1d7b

The vim editor opens and just change the commit message as follow

which exchange the position, ba5195a & 294b9ff

The order of commits

Delete Commit

Given following commits

If we want to delete 7a57d64

$ git rebase -i 44e1d7b

just directly remove the commit we want to delete

Then the commits would be as follow



Because sha1 encoding is too hard to memorize, so usually we will use label to mark the important commits such as the first runnable version …etc

for example, if we wan to give a ‘beta’ label to 62a13e6, then we can

$ git tag beta 62a13e6

Then there will be a tag on 62a13e6

We can see the information of tag with

$ git show beta

if we want to remove the tag

$ git tag -d beta




Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store