Remove last commit local undo the most recent commit Git github repository
First of all you should read this related article.
Option 1:
The solution is to first remove the last commit in local and then force push to Github
In local first do this:
git reset --soft HEAD^
Then
git status
So, now change what you want in your documents and files and then commit again.
git add .
git commit -m "new message"
Then push to github
git push origin branchName --force
If you want to still have it in your local repository and only remove it from the remote, then you can use:
git push origin +HEAD^:master
Then we can do
git status
and
git add .
git commit -m "message"
git puch origin master
Option 2:
If you want you can first remove the last commit from github:
git push -f origin HEAD^:master
After the above command if you still has access to that page commit in Github and refresh you will see:
then undo the last commit from local git by:
git reset HEAD^
Then
git status
In this way both local and github will be sync with each other. But all the changes in local will be safe and unchanged. The changes are in stage.
Then you see the modified versions of file which are not on the stage and they are not committed and you have to decide to git add . them and commit or undo every changes as I described in this article.
git checkout -- git checkout -- .
For more read:
Option 1:
Option 2:
Option 3:
you can find the hash of the commit you think it is good. then
git reset --hard HASH_OF_THE_good_Commit
then
git push origin -f name_of_the_branch
with these command you will loose all the changes after the good commit. So you should be careful to have a copy of them in a new branch.
— -
some useful command:make a branch:
git checkout -b new_branch_namego to branch A
git checkout name_of_the_branch_Arename a branch:
git branch -m old_name new_name
Bonus:
I would like to introduce two packages for Laravel that I have recently developed: Laravel Pay Pocket, a modern multi-wallet package, and Laravel Failed Jobs, a UI for the Laravel Failed Jobs Table. I hope they may be of help to you.
https://github.com/HPWebdeveloper/laravel-pay-pocket
https://github.com/HPWebdeveloper/laravel-failed-jobs
Also I’d like to hear your opinion on this article. If you have any doubt, question or suggestion please leave a comment below.
Have a very wonderful day!