Pagine

Monday 5 June 2017

Canceling a commit with git

The git revert command allows you to cancel your last unpushed commit. The type of cancel is only logical because Git doesn't drop phisically the commit but it creates a new commit that executes the opposite of your commit. A pushed commit is irreversible, so you cannot change it.

Example

The following example illustrates how to remove last pushed commit. First step, let's have a look at the last commits:
$ git log
commit dc2d9f3deda6f49902c1879b7b861fac51683865
Author: infoamodomio <infoamodomio@infoamodomio.com>
Date:   Thu May 25 12:19:01 2017 +0200
    Added a new file
Second step, We want to cancel the dc2d9f… commit:
$ git revert dc2d9f
Canceling this commit isn't necessary to enter the full commit ID, but just the first characters. Git will find it, but you will have to enter at least six characters to be sure that there isn't another commit that starts with the same characters.

No comments:

Post a Comment