Git revert local commit
WindowsGitMsysgitWindows Problem Overview
I have a git repo hooked up in phpstorm on windows. I committed a few change sets then pushed them to our "central repo". After this I have then made a few more commits. I no longer want these commits that have not been pushed to the central repo. How do I clean my working copy to be the same as the central repo (origin)?
Windows Solutions
Solution 1 - Windows
git reset --hard remotes/origin/HEAD
Solution 2 - Windows
git reset --hard remotes/origin/YOUR/BRANCH
better than /HEAD
because you won't see this:
$ git status
On branch MY/BRANCH
Your branch and 'origin/MY/BRANCH' have diverged,
and have 1 and 1 different commit each, respectively.
Solution 3 - Windows
If you feel sure about that and don't have any local uncommitted changes:
git reset --hard origin/master
where origin/master
is the branch you had pushed to.
The ref-log will still contain the reverted bits, until a garbage collect expires them. To revert the revert,
git reset --hard HEAD@{1}
Solution 4 - Windows
You can revert local commit by
git reset HEAD~N
where N is used to revert number of commits. An example:
if you have to revert single commit from local, then you can use
git reset HEAD~1
or git reset HEAD^
Solution 5 - Windows
As per my understading, you create some commit that you have pushed on central repo, after that you have create some more commit, but these are exist on local. These all did not push on central repo.
To remove/revert local commit;
git reset HEAD~{number_of_commit}
simply, you hit git log
on your command prompt and get list of commits. Have a look, how many commit you have created now and how many you have to revert.
for example, you have to remove.revert your two last commit then hit
git reset HEAD~2
There is one another way to reset your local repo with central repo. But, in this case your local commit will be removed and if other users push commit on central repo then your repo will be updated with that.
command is :
git reset --hard remotes/origin/HEAD