Due to some bad cherry-picking, my local Git repository is currently five commits ahead of the origin, and not in a good state. I want to get rid of all these commits and st
git reset --hard @{u}
* deletes all your local changes on the current branch, including commits. I'm surprised no one has posted this yet considering you won't have to look up what commit to revert to or play with branches.
* That is, reset to the current branch at @{upstream}
—commonly origin/<branchname>
, but not always
I had a situation where I wanted to remove a commit that wasn't pushed, but the commit was before another one. To do so, I've used the following command
git rebase -i HEAD~2
-> it will rebase the last two commits
And I used 'drop' for the commit signature that I wanted to remove.
If
Your branch is ahead of 'origin/XXX
' by 5 commits.
You can issue:
git reset --hard HEAD~5
And it should remove the last 5 commits.
For local commits which are not being pushed, you can also use git rebase -i
to delete or squash a commit.
Remove untracked files (uncommitted local changes)
git clean -df
Permanently deleting all local commits and get latest remote commit
git reset --hard origin/<branch_name>
Try:
git reset --hard <the sha1 hash>
to reset your head to wherever you want to be. Use gitk to see which commit you want to be at. You can do reset within gitk as well.