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
Thanks, we've got you!
Five Things To Love About the New UI
Are you using the New UI yet? Not yet? Let me tell you why it's the best thing since sliced bread! Let’s get it enabled and take a look around. The easiest way to do that is from the Settings cog at the top-right of the UI: PyCharm will need to restart, but that’s it; you’re done! In t…
Tutorial: Visual testing with pytest
If you are like many Python developers out there you LOVE writing code! Tests? Not so much. Whether it’s the concept of testing or the interface of testing tools, testing is a chasm not all developers cross. The Visual Testing with pytest tutorial aims to bring Python testing to the masses, tak…
Smart execution of R code
R plugin is announcing some helpful features to track execution of your R code: 1. Execute your R file as a runnable process, job. Jobs are shown in a separate tab in the R console. You can preview the job status (succeeded or failed), the duration of the execution, and the time you launched the …
New Database Features in PyCharm 2020.1
PyCharm 2020.1 comes with new Database export features that make exporting data easier. You can now see previews of the data that you want to export, letting you have a quick glance of what the data will look like. Furthermore, as many of our users prefer to export to Excel files, we've also adde…