how to undo last local commit using cmd in git

This tutorial shows you that how you can undo your last commit using CMD and this tutorial also teaches you some basic concepts of git


Following screenshot shows that how you can commit using CMD in git

  1.  check changes in repo using CMD git status
  2.  Git add your desired files using CMD git add file.php
  3. Git commit code with message git commit -m "some commit message"

Now we are assuming your last commit was wrong and happened incidentally
 

  1.  Git undo your last commit while leaving your working tree using cmd git reset 
    all changes will be reset and start showing in your working tree
  2. Do your desired changes in required files and run command again git add file.php
  3. Now You also need to update your git message according to your new changes run this command git commit -c ORIG_HEAD     

This will open an editor, which initially contains the old message from the old commit to edit this message please press -  and ctrl button at the same time 

After editing your desired message after that please follow the following steps

  1. Press esc
  2. And then :wq

Final step is to just push changes to git using cmd  git push
 

 Final commands are here

git commit -m "Something weired happened" 
git reset HEAD~          
git add file.php
git commit -c ORIG_HEAD    		


 


Tags:

git

Share:

Related posts