Reverting many commits in IntelliJ by one commit

Viewed 700

I'd like to revert many commits that were pushed overtime in IntelliJ, I was searching for relevant question but couldn't find any. Ideally I want the history to keep only one commit that would revert everything to the de0cbda enter image description here Is there any easy way to do it in IntelliJ? Or perhaps through command line?

1 Answers

If, as stated in your comment on my previous answer, you only want to revert changes done to one file in multiples commits just run :

git checkout de0cbda <PATH_TO_FILE>

Bellow, my previous answer, before OP specified that he only want to revert changes for one file

Yep, git revert command with -n flag will revert changes and stage them without committing.

Thanks to @ElpieKay's comment, check if your history is linear, if yes, reset your current branch to #1d7e8e5 and then run the following command :

git revert HEAD~14 -n

14 is the number of commits you want to revert.

If not, you can just list commits hashes in the git revert command :

git revert 1d7e8e5 0d2b8ea ... 39bdd21 de0cbda -n

At the end, review stashed changes and if you're happy with them just commit them with git commit -m "Message"

Related