In the previous post we have seen that how we can revert or undo a local or public git commit using git revert. In this post we are going to see some other ways in which we can Revert or Undo a commit using git. Yes, you have read it right only we are talking about only local commit.
Note : There are lot of things in life and git can’t be undone always .
Undo a commit using git amend :
Let’s consider a scenario where you have just started development of your application , and now you have lot of files to checkin into the git repository so for doing that you have to do a local commit first, of all those files. After doing this commit you have realized that , few files have been missed that was also supposed to go in the same commit or you just want to change the commit message only .Constraint is that all these changes should belong to a single commit and not to multiple commits. You can achieve the same by using git commit with amend.
Let’s understand the whole process step by step.
First I have changed two files file1.txt and file2.txt in my system , as you can see the same with git status.
git commit –m “Intentionally missing file2 in the commit” file1.txt
Git add file2.txt
git commit -–amend
Latest posts by Saurabh Jain (see all)
- java.lang.IncompatibleClassChangeError: Found interface org.apache.hadoop.mapreduce.TaskInputOutputContext, but class was expected - August 8, 2014
- org.datanucleus.store.rdbms.exceptions.MappedDatastoreException: INSERT INTO “TABLE_PARAMS” – Hive with Kite Morphlines - July 17, 2014
- java.io.IOException: can not read class parquet.format.PageHeader: null – Hive - July 12, 2014