Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git revert local commit

People also ask

How do I revert a git commit locally?

To undo your local commit you use git reset <commit> . Also that tutorial is very helpful to show you how it works. Alternatively, you can use git revert <commit> : reverting should be used when you want to add another commit that rolls back the changes (but keeps them in the project history).

How do I revert a commit in local and remote?

To undo the last commit from a remote git repository, you can use the git reset command. command. This will undo the last commit locally. command to force push the local commit which was reverted to the remote git repository.


git reset --hard remotes/origin/HEAD

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.

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}

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^


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