0

Is it possible to undo one or two faulty commits I have made to Github. I'm not very good at coding either so if there's a way to do it without coding, that would be great.

Thank you very much

0

1 Answer 1

2

You can do this via doing the following command in your local workspace:

git reset --merge <hash>

Where <hash> is the commit prior to the commits that you want to revert.

The above command is enough if you haven't pushed to GitHub. If you have pushed to GitHub, you then run the following to force an update of the remote branch:

git push --force origin <branch>

(Note: This is assuming that your remote is named origin, but rename as appropriate.)

Note that this re-writes history on the remote branch, and is not recommended if other developers are using the same branch. If you know who the developers are, you can communicate with them to delete their local copies of the modified branch and ask them to run git fetch to get a new copy of the branch.

Sign up to request clarification or add additional context in comments.

3 Comments

Don't use the --hard flag, use --merge in order to avoid losing changes in working directory (either staged or unstaged).
Huh? When do you 'git push' to GitHub... before or after 'git reset'?
@zipzit - After git reset. git reset updates your local branch pointer to the <hash> commit. git push --force updates the remote branch on GitHub.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.