My First Post      My Facebook Profile      My MeOnShow Profile      W3LC Facebook Page      Learners Consortium Group      Job Portal      Shopping @Yeyhi.com

Pages










Tuesday, January 22, 2019

How to undo a Git commit that was not pushed

To undo a Git commit that was not pushed, you are given a few major options:

Method 1:
Undo the commit but keep all changes staged
git reset --soft HEAD~; 


Method 2:
Undo the commit and unstage the changes
git reset HEAD~; 
or 1 git reset --mixed HEAD~; 


Method 3:
Undo the commit and lose all changes
git reset --hard HEAD~;


Method 4:
In case you just want to rewrite the commit message, you could use:
git –amend instead.

eg: git commit --amend -m "an updated commit message"



However if you only want to undo Last Git Commit

Then easiest way to undo the last Git commit is 
$ git reset --soft HEAD~1


I will add following more helpful commands to check commit history, go back to a commit, and remove commits etc:
  1. git log
  2. git log --oneline to simplify the output:
  3. To test a specific commit: git checkout . You will be in 'detached HEAD' state. You can look around, make experimental changes and commit them, even create a new branch from here using git checkout -b new_branch_name
  4. To fix the detached head issue: git checkout
  5. Undo this commit: git revert . This will create another commit operation in github

Free Additional Tip:
To Undo a git add i.e. remove files staged for a git commit
1. git reset filename.txt OR
2. git reset *
After this you can add again the required files


Cheers :)
-Anwar Jamal Faiz


Read some of my other posts related to Git tricks below :

7 comments:

  1. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging.
    Authorized ipad service center in Chennai | Authorized ipod service center in Chennai | ipad service center in chennai | ipod service center in chennai | ipad service center in chennai

    ReplyDelete
  2. It should be noted that whilst ordering papers for sale at paper writing service, you can get unkind attitude. In case you feel that the bureau is trying to cheat you, don't buy term paper from it. single Muslims

    ReplyDelete
  3. شركه الصفرات المصنفه رقم واحد علي مستوي الخدمات المنزليه من حيث التنظيف وجوده الخدمه التي تقدمها الي عملائها بجانب الخصومات الهائله التي تمنحها بنسبه كبيره الي جميع عملائنا الموجودين داخل المملكه العربيه السعوديه حيث نتمتع بوجود نخبه من العماله المتميزه ذوي الخبره في مجال التنظيف وجميع الخدمات المنزليه ووجود احدث واجود المعدات المستخدمه في جميع المجالات التي تخص مجال الخدمات بشكل عام ووجود خصومات كبيره عليكم فقط الاتصال بشركتنا
    شركة مكافحة الحمام بالرياض
    شركة الصفرات لمكافحة الحشرات بالرياض
    شركة الصفرات للتنظيف بالرياض
    شركة الصفرات لعزل الخزانات بالرياض
    شركة الصفرات لتسليك المجاري بالرياض
    شركة الصفرات لتنظيف الخزانات بالرياض
    شركة الصفرات لكشف التسربات بالرياض
    شركة الصفرات لنقل الاثاث بالرياض
    ونذكر عملائنا باننا متاحين للعمل في اي وقت خلال 24 ساعه يوميا ووجود خصومات تصل الي 40% وضمان مستوي الخدمه

    ReplyDelete
  4. تقدم شركتنا افض الخدمات لعملائنا في مجال خدمات النظافه بكل انواعها في الممكله العربيه السعوديه والتي تساعد علي التخلص من الاوساخ والحشرات وتقدم شركتنا افضل العروض في مجال الخدمات المنزليه بحيث ان نكسب رضا عملائنا بجانب الخصومات التي توفرها الشركه والي جانب ايضا العماله المتميزه ذوي الخبره في المجال بجانب احدث المعدات الموجوده لدينا وسرعه الاستجابه الي عملائنا ونتشرف باتصالكم بنا في اي وقت
    شركة الصفرات لنقل الاثاث بالرياض
    شركة الصفرات لتسليك المجاري بالرياض
    شركة الصفرات لعزل الخزانات بالرياض
    شركة الصفرات لكشف التسربات بالرياض
    شركة الصفرات للتنظيف بالرياض
    شركة الصفرات لمكافحة الحشرات بالرياض
    شركة الصفرات لتنظيف الخزانات بالرياض
    شركة المثالية لنقل العفش بالدمام
    شركة المثالية لمكافحة الحشرات بالدمام
    شركة المثالية للتنظيف بالدمام
    علي عملائنا فقط الاتصال بالارقام الموجوده داخل الموقع لتصلكم شركتنا في اسرع وقت مع تقديم افضل خدمات التنظيف مع افضل الخصومات


    ReplyDelete
  5. شركة تنظيف مجالس بالجبيل


    شركة تنظيف مجالس بالخبر



    شركة تنظيف مجالس بالدمام



    شركة تنظيف كنب بالخبر


    شركة تنظيف كنب بالدمام



    شركة تنظيف كنب بالجبيل



    شركة تنظيف كنب بحفر الباطن



    شركة تنظيف فلل بالخبر



    شركة تنظيف فلل بالجبيل



    These curtains will make them prone to tangles

    What is the only way to hang the bed?

    Place towels on the floor below the curtain.

    Fill a spray bottle with 2 cups warm water and 2-3 drops of dish detergent

    Wipe clean with a damp, damp cotton cloth, and lightly rub on dirty areas as needed.

    Allow to dry and remove the bed sheet background.

    Waste residue

    Some velvet curtains are machine washable while others need dry cleaning. Check the manufacturer's label

    In general, lined velvet curtains should be treated as dry and clean only.

    ReplyDelete