Mastering PyCharm Transcripts
Chapter: Source control
Lecture: Local history

Login or purchase this course to watch this video and the rest of the course contents.
0:01 Now you know how to use a proper source control system like git,
0:04 it will be not super different for Mercurial or for Subversion or any of those other things.
0:09 But— you don't always check in every change
0:12 and sometimes you really would like better more fine grained accuracy
0:19 for the changes that have happened to your files.
0:21 Like, if you make a change and then you decide to throw that change away
0:25 or you keep going and you end up breaking something
0:28 you are like oh, I wish I had checked it in, like 30 minutes ago
0:31 and then I could roll it back to there, but I got a roll it farther back
0:35 because that's all the history that I have in my source control.
0:38 Git solves this little bit with local check ins
0:41 and you can have more fine grained,
0:43 but still I contend that there are times when you are like
0:45 I really wish I had a version of this, and you don't.
0:48 So, PyCharm has this amazing thing called local history
0:51 so independent of whether we were in a git repository
0:55 or had any source control configured at all,
0:58 local history is always active
0:59 and you come down here and go to a particular file and view local history,
1:03 there's not a whole lot to it,
1:05 we could put a label or we could just show the history, watch this.
1:08 Here is the life-cycle of this program.
1:11 Back here, we had zero files
1:16 and then we created this one file here, right,
1:21 and then we made some changes,
1:25 so if you click through, it just shows you
1:28 all the various changes that happen, now it is starting to get interesting.
1:32 l'll show you these files, how they've changed over time,
1:36 these are identical, here is another one,
1:39 okay, so basically you get the various changes that you've seen over time.
1:45 Now, there's a bunch of changes that have actually nothing to do with this
1:49 so I'll just stay here, but this is really, really awesome
1:53 we've got local tracking of any change,
1:56 and also it shows you where we checked in the other changes.
2:00 Let's go and make some more changes
2:02 let's suppose first I'll put a label
2:05 so this will be factored, saved, right
2:09 you don't have to put labels but you can.
2:11 So let's go over here and let's import random
2:15 and let's go and say start=random.randint
2:23 and we're going to start somewhere between 90 and 110
2:28 and we're going to end by going to let's say 130 140
2:39 so we'll come down here and instead we're going to say start
2:42 and let me put a save, end
2:45 and maybe let's put one line here again.
2:50 So let's just run it and see what happens
2:53 all right it looks like it went from
2:56 way back 105 to 137 was what it came up with the end.
3:00 So that seems totally reasonable.
3:03 Now let's go back to this local history one more time.
3:06 Now we can see some more meaningful changes
3:08 so over here, we tagged it,
3:10 notice when we do a commit it actually tags it automatically
3:13 but over here we get that as well.
3:16 Now you can see we factored, we sort of labeled and we saved it
3:21 and we made one change we came down here like this
3:25 and we said okay, we'll go and have this version
3:29 and then, we can get this one, this is where we added that new line there,
3:33 so you can see, we started out with no randomness
3:38 and then we added that random,
3:40 I think this def is the current one.
3:43 So this is what it was before
3:46 and then we go up here and then we added that new line down there.
3:51 So things kind of moved around a little bit
3:54 but this is really, really helpful, I would say at least one time,
3:58 I badly lost some file that I thought was in source control
4:02 and for some reason it wasn't, I deleted it and then I needed it back actually,
4:07 it turns out I was able to use local history to get it back exactly,
4:10 so I don't use this often but when I do use it it's like really, really hopeful.
4:15 It's also great if you're working in a project that doesn't have source control set up yet,
4:19 this is kind of like your wimpy source control,
4:22 super, super cool stuff, you can even do a little revert here.
4:26 Okay, so local history— definitely, definitely check it out
4:31 it's a parallel, independent version control that only lives in your project files.