💾 Archived View for gemini.ctrl-c.club › ~nttp › writing › source-control.md captured on 2024-08-31 at 15:20:55.
⬅️ Previous capture (2024-08-18)
-=-=-=-=-=-=-
# Gettin started with source control 2024-03-12 Seasoned programmers probably know all this already, so bear with me. If you've done programming for any length of time, and/or more seriously than the occasional shell script or web page, you might have found yourself in the following situation: - you're taking snapshots of your work at regular intervals in the form of dated archives; - now you want to know what exactly you changed since the last snapshot; - or for that matter see the changes between successive snapshots, and the reasons for those changes. The better solution is to to use a version control system (VCS for short), also known as a source code manager (SCM). These are command-line tools with optional GUI front-ends that can efficiently store successive revisions of your files, along with a timestamp and commit message. You can look back, or even go back, any time you like. You can figure out when a bug crept in, try different ideas, keep track of work done or collaborate with other people without breaking stuff. My new favorite is [Mercurial][]. It's in the repos of most Linux distributions (and Haiku), and very easy to start with once installed: simply `cd` to your work directory and enter: hg init; hg add; hg commit At this point Mercurial will prompt you for a commit message – here's that notion again. Always enter something. Half a line of text is enough, like "added initial files", but this is how you find your place again. Yep, there's some bureaucracy involved; the main downside of source control. Let's look over some basic notions: - A "repository" is where your VCS keeps the project history. With most modern systems it's a hidden directory next to your files, in this case called `.hg`. The `init` command creates a new repository, so you only need to give it once. - Then you have to `add` the files you want tracked (by default all of them). You can change your mind before you commit. - Every `commit` stores a so-called revision, i.e. all the changes you made since last time. You can see these changes with `hg status` and `hg diff`. - Use `hg log` to check out the revision history. - Enter `hg serve`, then point your web browser at `localhost:8000`; now you can click comfortably through your files and revisions, or browse the built-in help. There are many advanced features, but these seven subcommands are enough 80% of the time. Even better, other systems work the same way, with small differences. Take [Fossil][] for example: - Each repository is a single file, kept elsewhere on your drive. - First `init` a repository, then `open` it in an empty folder, *then* move your files into it and `add` them. - Use `timeline` instead of "log", and `ui` instead of "serve". Fossil is a single, small executable that doesn't have to be installed. It has some slick features, but the added bureaucracy pushed me away. Like Mercurial, it's as popular as it's obscure: many projects use Fossil, few talk about that. Speaking of which: nowadays most people equate source control with software forges: centralized websites that host repositories online, such that entire teams can work on the same project. You've probably heard of behemoths like GitLab or SourceForge, but cozy little places like [tildegit][] are just as good. If anyone uses them, anyway. Just don't let anyone tell you there's only one system you can use, or one site. For example, talking to some friends about it revealed that at least two of them use Subversion: a more traditional alternative, older than most but simpler, that's still actively developed. And newer systems can talk to it just fine. In fact they can often read and write each other's repositories, so you won't be locked in. Choose the one that works best for you. I first learned about source control around 2006, and used it all the time by 2009, but then started slipping and went back to my bad old ways for some years. Getting back into the habit hasn't been easy. But when I caught myself taking snapshots then wondering what exactly was in them, the writing was on the wall. Do yourself a favor and try this way of working for a while. [Mercurial]: https://www.mercurial-scm.org/ [Fossil]: https://fossil-scm.org/ [tildegit]: https://tildegit.org/