I have made some changes to my code and then did a: git add . git commit git push origin master.
Now i realise that i have made some mistakes and i want to get back the code of the previous commit and then re do the changes and push them back to the server.
This is the git log output:
commit 3254c7668610a86eb930798c3c50fb5e1c298cbf
Author: Subhayan Bhattacharya <[email protected]>
Date: Wed Sep 6 00:53:39 2017 -0700
Made changed to downloadpkgapp.sh
commit c6577344eaa7ed1ac7fc911892cf85f66a0ac0b9
Author: Subhayan Bhattacharya <[email protected]>
Date: Wed Aug 16 02:56:17 2017 -0700
commiting changes to file CallProgram.py
commit 3839fa51edb20812c10d96f40b36aaa4fada9200
Author: dheeraj.mittal <[email protected]>
Date: Sun Jun 11 11:17:41 2017 +0200
added execute permission command for application package
Someone please help me with the same. I have trouble understanding GIT a lot. So if someone can also explain whatever steps are suggested that would be great.
I suggest you to use an git graphical interface like Git Extensions. It will be more easy to follow what is happening...
With Git Extensions you can do:
1) be sure that you don't have any change that is not commited. Include any change in a commit to be sure you don't loose it
2) create a new branch in your last commit: click your last commit, press right button and select "Create new branch". In the dialog do not select the "Checkout after create option". Call the new branch something like "incorrect"
3) select your last correct commit and press right button and select "Reset current branch to here". Select "Hard" reset type.
4) redo all the code modifications with the commits you need
5) press "push" button and in the push dialog select "Options" and check "Force with lease" this will force the update of the server to your new commit.
Be careful!: if anyone has pulled your changes with your previous commits you will create a lot of confusion if you change the commit history in the server. If there is any chance someone has your previous commit you should maintain your commit history with the errors and do the corrections in new commits.
When you are sure you will not need it you could remove the "incorrect" branch.