I have local commit that are not on any branch that I would like to delete. I don't want to rebase them, I really want to delete them, and loose all the content related to these commit.
Is their a command to do so ?
So far I've tried interactive rebase as many suggested, but it just move commit around, it doesn't delete them. I've also tried to use reflog delete, but I can't figure out how to pass a specific commit Id to the command.
Here's the working tree:
o [master] Commit #6 | o Commit #5 | | o Commit #4 |/ o Commit #3 | o Commit #2 | o Commit #1
I want to physically delete the commit #4.
To remove the last commit from git, you can simply run git reset --hard HEAD^ If you are removing multiple commits from the top, you can run git reset --hard HEAD~2 to remove the last two commits. You can increase the number to remove even more commits.
Use git prune to remove orphaned/unused branches If you see any branches in there that you don't want, you can use the command git branch -d <branch name> . If you want to delete the branch called badbranch, use the -D switch to force the deletion if it doesn't work: git branch -d badbranch .
The easiest way to undo the last Git commit is to execute the “git reset” command with the “–soft” option that will preserve changes done to your files. You have to specify the commit to undo which is “HEAD~1” in this case. The last commit will be removed from your Git history.
Your commits aren't gone (yet) When you use --force, you are adding new commits to Git and updating the branch reference of your branch. You have only orphaned the existing previous line of work as it is no longer referenced by anything.
If the commit is not referenced by anything, it will be removed with git's garbage collection, in time.
If you want to force it before hand, use git gc --prune=now --aggressive
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With