Feature Spotlight: Tracking code changes with Local History
Today I’d like to highlight the one of the top features that saves you from unexpected changes in your code and keeps things on track – Local History. This feature exists in PyCharm for a long while, but it’s worth to talk about it once again!
Note: Local History is available in both PyCharm Professional Edition and PyCharm Community Edition.
Local history is the way for PyCharm to track all your local personal changes to your project files. It simply expands the VCS functionality for you locally. When developing, there are constant small changes in the code. I bet you’ve had occasions when you needed the information about code changes, but the version control systems couldn’t help you because they track and compare differences only between committed versions – you just can’t commit so often to have a track of all your small changes. Some local changes between commits are unnoticed for VCS and this is where Local History comes to the rescue!
So let me show you how it works:
When editing, you can open local history by simply right-clicking on any file, and go to Local History | Show history:
This will show you the changes of your file, including commits, external changes, some major refactorings that happened, and just other basic changes. And then once you’re on one of these changes it shows you the diff of the file:
You can scroll down and revert any of the changes that you want by clicking the icons to insert the old code or remove code, or by simply reverting the entire file by right-clicking and selecting Revert or Create Patch:
You can also select a block of text and only show the changes for that selection. So select a code snippet and click Show history for selection:
You can also select an entire directory or your entire project – do “show history” on a directory or project and it’ll show you the list of files that have changed in your local history. And then once you find a file that you want you can double click on it to bring the diff for that file in that copy of the history:
You can also invoke local history from the keyboard by using Alt + Backquote and going down to Local history | Show history. That’s just a different way to invoke it.
Last but not least, at any time you can do Local history | Put label, give the label a name and now have a custom label which is stored in local history and lets you view your file’s state at the time you added the label:
As you can see Local History is just the PyCharm’s way of tracking your personal changes. That isn’t something that is shared across your project. It just tracks local changes to files, keeping everything in its history: external changes, commits, regular edits, etc.
I know quite a few times when it actually saved developers from a system crash consequences or helped when VCS just wasn’t enough. Sometimes you could really use that extra hand from your IDE.
So in case you’ve lost some files or made some unexpected changes in your code – everything is still in the PyCharm memory. Check it out!
See you next week!
Subscribe to Blog updates
How to Connect Django With MongoDB
Learn how to use Django and MongoDB together to create a web application in PyCharm. Follow our step-by-step tutorial to connect MongoDB with Django.
New Low-Impact Monitoring API in Python 3.12
Python 3.12 adds the new low-impact monitoring API, enabling debuggers, profilers, and similar tools to run code at almost full speed.
Guest Post: Four Ways To Quickly Display OpenCV Images During Debugging
This is a guest blog post by Adrian Boguszewski, author of OpenCV Image Viewer Plugin. The average programmer makes 70 errors per 1,000 lines of code and spends 75% of their time on debugging (source). In computer vision (CV), this process may involve not only fixing the code but also checking th…