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









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.



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 :

5 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. فالحشرات في البيت أمر مزعج، ومن يراها يظنّ أنّ أصحاب البيت غير مبالين بنظافته، وهذا أمر لا يمكن احتماله؛ نظراً لأنّها تترك أثرها في كل مكان في البيت، والحقيقة الواردة عن هذه الحشرات أنّها تنشر الأمراض في كل البيت، وتؤدّي إلى عدم الشعور بالراحة داخل المنزل المخصص في الأصل لننال القسط الكافي من الهدوء، وحديثنا اليوم سيدور عن طرق القضاء عن الحشرات بكافة أنواعها، ومن أهمها ما يلي:

    شركة رش مبيدات بحائل
    شركة رش مبيدات بالاحساء
    شركة رش مبيدات ببريدة
    شركة رش مبيدات بابها

    ReplyDelete