For every IDE git related command, once you perform it via UI, you can see the input of the command in the Console log in your git window.
Drop commit does a rebase --interactive --no-autosquash command followed by a hash of a commit made before the commit you are dropping. It interactively rebases your branch on that previous commit and deletes the commit you have selected. This is used to delete the commit entirely and re-write the history.
Undo commit does a soft reset where all the changes of the commit are staged in your changelist.
You can read more about git reset here: https://www.w3schools.com/git/git_reset.asp?remote=github
You can learn more about interactive rebase here: https://www.youtube.com/watch?v=bPX9VHjviEM
Answer from Dino Letic on Stack OverflowFor every IDE git related command, once you perform it via UI, you can see the input of the command in the Console log in your git window.
Drop commit does a rebase --interactive --no-autosquash command followed by a hash of a commit made before the commit you are dropping. It interactively rebases your branch on that previous commit and deletes the commit you have selected. This is used to delete the commit entirely and re-write the history.
Undo commit does a soft reset where all the changes of the commit are staged in your changelist.
You can read more about git reset here: https://www.w3schools.com/git/git_reset.asp?remote=github
You can learn more about interactive rebase here: https://www.youtube.com/watch?v=bPX9VHjviEM
Drop commit simply 'drops' a commit from git history without leaving any trace of it occuring.
Undo commit does something similar while keeping the changes that had been done. With the use of --force-push, this command allows to rewrite the history of a remote repo as well.
Drop commit
How to completely remove a commit from git history
There is no difference by default; it's just another way to say the same thing.
But, if you set rebase.missingCommitsCheck to warn or error, then removing a line will trigger a warning (useful for detecting a messed-up cut-and-paste).
Then setting the line to drop explicitly tells Git that you want to drop that commit, and no warning is shown for it.
There is in fact another small difference:
You can explicitly "drop" all commits. The effect will be the same as a reset.
However if you just delete all lines, then git will tell you "Nothing to do".
Usually you would not use rebase anyway in that case. I learned the difference only when I tried to explain removing a commit with rebase to a co-worker using a dummy commit.
Careful: git reset --hard WILL DELETE YOUR WORKING DIRECTORY CHANGES.
Be sure to stash any local changes you want to keep before running this command.
Assuming you are sitting on that commit, then this command will wack it...
git reset --hard HEAD~1
The HEAD~1 means the commit before head.
Or, you could look at the output of git log, find the commit id of the commit you want to back up to, and then do this:
git reset --hard <sha1-commit-id>
If you already pushed it, you will need to do a force push to get rid of it...
git push origin HEAD --force
However, if others may have pulled it, then you would be better off starting a new branch. Because when they pull, it will just merge it into their work, and you will get it pushed back up again.
If you already pushed, it may be better to use git revert, to create a "mirror image" commit that will undo the changes. However, both commits will be in the log.
FYI: git reset --hard HEAD is great if you want to get rid of WORK IN PROGRESS.It will reset you back to the most recent commit, and erase all the changes in your working tree and index.
git stash does the same except you can restore it later if you need, versus permanently delete with reset hard mode. Check your stashes by using git stash list and git stash show 'stash@123'
Lastly, if you need to find a commit that you "deleted", it is typically present in git reflog unless you have garbage collected your repository.
If you have not yet pushed the commit anywhere, you can use git rebase -i to remove that commit. First, find out how far back that commit is (approximately). Then do:
git rebase -i HEAD~N
The ~N means rebase the last N commits (N must be a number, for example HEAD~10). Then, you can edit the file that Git presents to you to delete the offending commit. On saving that file, Git will then rewrite all the following commits as if the one you deleted didn't exist.
The Git Book has a good section on rebasing with pictures and examples.
Be careful with this though, because if you change something that you have pushed elsewhere, another approach will be needed unless you are planning to do a force push.
Hello, I have an unusual git repo which I'm using to create backups of a project with quite a few non-source code files, which have changed more than I expected. I'm actually thinking git might not have been the best tool for the job here, but I'm familiar with it and will probably continue to use it. This is just a personal project, and I'm the only contributor.
What I'm looking for is a way to completely erase a git commit, preferably give the git commit hash. The reason for this is because I have several consecutive commits which change a variety of large files, but I really don't care about the commits in between those which I think would be sufficient to keep. I was thinking there should be a way to remove the unneeded intermediate commits with prune, but am not sure what the best approach here is - thanks!