If you go to Changelist -> Log, and there select the commit, you've got a change detail in the right panel. There you can select all and click a button (or right click -> revert selected changes).
Answer from c0stra on Stack OverflowIf you go to Changelist -> Log, and there select the commit, you've got a change detail in the right panel. There you can select all and click a button (or right click -> revert selected changes).
I know of only one way and it's not as good as doing it command line.
First create a reverse patch. Go into the log, choose any commit and select create patch, check reverse patch and save it anywhere.
Then go into VCS menu and select apply patch and choose the file you just saved.
Commit those changes.
Still, I would go with doing it command line. Gives a proper automatic commit message as well.
How to revert my git remote branch into previous commit in intelliJ? - Stack Overflow
Git + Intellij - How to revert a local commit? - Stack Overflow
Undo multiple commits but keep local changes.
You can reset the head on your checked out branch to any hash you'd like in your history. It won't make changes to the files in your workspace without the -hard flag, so just do a reset to whatever commit you'd like, without passing it -hard.
This, of course, ignores whatever "Intellij" is, but you asked a question in "r/git", and that's how what you asked is addressed with Git.
More on reddit.comintellij idea - How to revert a unpushed git commit - Stack Overflow
Videos
If it's a single commit that you want to place back into staging, then you can do the following command:
git reset --soft HEAD^
You can replicate that in IntelliJ through these steps:
- VCS > Git > Reset HEAD
- Change reset type to "Soft"
- Change commit to
HEAD^
There are three concept in Git, working directory, staging area and git repo. The parameters 'mixed/head/soft' you said corresponding to the three concept above. Parameter mixed only change the state of git repo, parameter soft change staging area and git repo, and the third parameter change all of three.
Im working in enterprise and Ive never had to do this before . I accidentally pushed the target folder. How would I revert the commits without losing my changes safely in IntelliJ. I have googled but I am afraid in case it messes up my work
I need to delete the remote branch then back the changes. .
You can reset the head on your checked out branch to any hash you'd like in your history. It won't make changes to the files in your workspace without the -hard flag, so just do a reset to whatever commit you'd like, without passing it -hard.
This, of course, ignores whatever "Intellij" is, but you asked a question in "r/git", and that's how what you asked is addressed with Git.
Besides the suggested commands, you might also be interested in bfg_cleaner
In the latest version, you simply go to version control, right click the commit and select Undo Commit. This will put the changes back into a change list (so you can edit if needed) and remove the commit. You can remove the change list / revert the changes if you want them gone completely.
Using the Reset HEAD option should work too, just make sure to select a correct target and set an appropriate reset type (Mixed if you want to keep the changes, Hard if you want the changes gone too). To make it easier to find the target, you can find a Reset Current Branch to Here option when right clicking a commit in version control.
In that VCS > Git > Reset HEAD dialog from IntelliJ, you wanted to:
- select
Softas theReset Type(to keep the changes of the undone commit) - use
HEAD^as the commit (to point 1 commit back in the history of your branch)

That is equivalent to the following git command: git reset --soft HEAD^
You can revert individual commits with:
git revert <commit_hash>
This will create a new commit which reverts the changes of the commit you specified. Note that it only reverts that specific commit, and not commits that come after that. If you want to revert a range of commits, you can do it like this:
git revert <oldest_commit_hash>..<latest_commit_hash>
It reverts all the commits after <oldest_commit_hash> up to and including <latest_commit_hash>. Some versions of git also revert the <oldest_commit_hash> itself, so double check if that commit gets reverted or not. You can always drop the latest revert commit (which reverts the oldest commit) with g reset --hard HEAD~.
To find out the hash of the commit(s) you can use git log.
Look at the git-revert man page for more information about the git revert command. Also, look at this answer for more information about reverting commits.
Extra note for re-applying reverted commits:
Usually you revert commits because you discovered the commits that you pushed turn out to have an issue. Then you first want to restore the repo to a stable state, before you continue to fix the issue. So then you would first do the git revert, as described before. Then push those revert commits, so the remote is stable. After that you would want to re-apply the reverted commits locally, so your local repo's files are back to the state before the revert. Then you can fix the issue.
To re-apply the reverted commits, you have to revert the revert commits. So what you would do, is to again execute the git revert command, but then with the range of commits of the revert commits. So your new revert commits will revert the previous revert commits. Then your files are back to the state before the first revert. Then you can fix the issue, create a new commit with the fix, and then push all the new commits.
A solution that keeps no traces of the "undo".
NOTE: Don't do this if someone already pulled your change (I would use this only on my personal repo.)
Run:
git reset <previous label or sha1>
Note: previous means the commit before the erroneous commit
This will re-checkout all the updates locally (so git status will list all updated files, meaning, the files you changed/added/.. and were committed).
Then you "do your work" and re-commit your changes (Note: This step is optional).
git commit -am "blabla"
At this moment your local tree differs from the remote
git push -f <remote-name> <branch-name>
will force the remote branch to take this push and remove the previous one (specifying remote-name and branch-name is not mandatory but is recommended to avoid updating all branches with update flag).
!! Watch-out some tags may still be pointing removed commit !! how-to-delete-a-remote-tag