Tips for Faster Debugging in IntelliJ
Tags: java, discuss, programming, productivity
Published: 2022-04-22 03:34:00

Top IntelliJ tricks to debug issues faster. (excluding the debugger)

## Fold Logs

Running an application can produce a lot of console output. Most of it is not useful and comes from third party libraries. You can fold console output lines coming from these libraries. This will help you focus on the important information.

- Select the class name on the log line and right click 
- Select "Fold lines like this".

It will open a window and add this class to the list of classes to fold. You can further edit this class name to a package name to fold all classes in that package.

![Fold Lines Pop-up in IntelliJ](https://pbs.twimg.com/media/FQ4Q-3kVkAAW6D2.png)

## Search With Google

You can trigger a Google search from anywhere in the IDE - code, console, log files, text files, etc.

For e.g., when you see an error in the logs, 
- Select the piece of text you want to search 
- Right click 
- Search with Google.

![Search with Google Option](https://pbs.twimg.com/media/FQ4Q_R5VkAAbZLo.png)

While this is a trivial thing, it gets you to StackOverflow faster. 

If you want to take this one step further and stop the monopoly, use the Smart Search plugin which lets you use custom search engines. 

You can even search on StackOverflow directly and cut out the middleman.

![Custom search engine settings in Smart Search](https://pbs.twimg.com/media/FQ4Q_sgVsAEIEiJ.png)


## Compare files with Clipboard

You can compare contents of a file with the content in the clipboard. This is useful in comparing files which are not part of version control.

This can also serve as a quick way to compare and merge two files.

A usual usage scenario is to compare configuration files.

![Compare with clipboard](https://pbs.twimg.com/media/FQ4RAFQVgAEhCN9.png)

## Show Git History for a Piece of Code

You see a code, but you don't know what it does (or why it does what it does). 

To get an idea, you need to know why the code was written and/or who wrote it. 

Find it out using the Git history. 

- Select the piece of code 
- Right click 
- Go to the Git section and select "Show history for selection".

This will list down all the old commits which included changes in the code. 

![Show Git History](https://pbs.twimg.com/media/FQ4RAnwUYAEpNxr.png)

## Compare code with a working copy

Something worked in the past, but now it doesn't. A great way to debug it is to check the changes that have been made to it since then.

There are multiple ways to do this.

1. Use the Git option "Compare with branch" and compare the current code to the code in a branch that worked fine.
2. Use the Git option "Compare with Revision" and compare it to the code in a commit that worked fine.
3. Compare entire current branch with another branch. This is useful to understand multiple changes together instead of looking at a small piece of code.

## Local History

You can see the history of changes you made to a file in the local history. IntelliJ maintains a local history for each file (yes, even uncommitted code is safe).

This can be helpful when recovering from accidental deletions or to recover an intermediate state of a file.

For e.g. You made the code work, tested it and then went on to refactor it before committing. If the code doesn't work, you can recover the previous working state of the file from the local history or just compare it to understand what you did wrong.

![John Cena in Suicide Squad Meme - used to portray IntelliJ does everything Eclipse does, but better](https://pbs.twimg.com/media/FQ4RB0iVIAAu7Pt.jpg)

--- 
Thank you for reading. [](url)

More importantly, if you have any tips of your own, feel free to share them in the comments.