If your excess commits are only visible to you, you can just do
git reset --hard origin/<branch_name>
to move back to where the origin is. This will reset the state of the repository to the previous commit, and it will discard all local changes.
Doing a git revert makes new commits to remove old commits in a way that keeps everyone's history sane.
If your excess commits are only visible to you, you can just do
git reset --hard origin/<branch_name>
to move back to where the origin is. This will reset the state of the repository to the previous commit, and it will discard all local changes.
Doing a git revert makes new commits to remove old commits in a way that keeps everyone's history sane.
Delete the most recent commit, without destroying the work you've done:
git reset --soft HEAD~1
Delete the most recent commit and remove changes:
git reset --hard HEAD~1
Hi there –
I've made a complete mess of my repo. Three branches are now in an unreliable state.
Unfortunately, much of the mess is already on GitHub.
I'd like to completely delete all commits that were made after a certain point, so that I can start over with a clean slate.
How can I do this, in a way that will also delete the problematic commits from GitHub?
Unfortunately, I'm not a very proficient Git user – so anything about rebasing, reflogs, etc. is going to lose me very quickly. Please, speak slowly and use small words :)
Thanks for any suggestions.
ETA: I found this StackOverflow answer, which recommends doing git reset --hard <last_working_commit_id> to delete the bad commits, and then using git push --force to delete them from GitHub. This sounds easy, but is there anything I should consider before using this technique?
I would like to organize my PR after my feature is done by removing all of my 'work in progress'-commits and creating new commits that group files to improve the readability of my PR.
I have tried using git reset, but that only unstages changes that have been added using git add . & all files that are already committed seem to be out of reach.