←back to thread

1062 points mixto | 8 comments | | HN request time: 0.001s | source | bottom
1. wodenokoto ◴[] No.42944183[source]
On the promise of going back in time, I’m finding myself getting more utility of VS Codes timed snapshots than my own commits.

I find it hard to judge when things are in a good enough state to commit and especially good enough to have a title.

I might start writing a new function, decide that I want it to be a class only to give up the class and wanting to return to my almost complete function. Snapshot works pretty well for that, but got isn’t really centered around snapshots and doing good snapshots is not straightforward, at least to me.

What do you guys do?

replies(4): >>42944257 #>>42944328 #>>42947021 #>>42948158 #
2. shandor ◴[] No.42944257[source]
A commit is literally a snapshot :) It is also very easy to make.

Stop worrying about titles and content and commit to your heart’s content.

When ready, restructure those snapshots into a coherent story you want to tell others by squashing commits and giving the remaining ones proper titles and commit messages. I use interactive rebase for that, but there are probably other ways too.

3. foobarbaz33 ◴[] No.42944328[source]
> I find it hard to judge when things are in a good enough state to commit

Work in a feature branch. Commit often. Squash away the junk commits at the end.

> ...and especially good enough to have a title.

Who needs a title? It's perfectly fine to rapid-fire commits with no comment, to create quick save points as you work. Bind to a key in your editor.

I treat commits in a private branch the same as the undo log of the text editor. No one cares about the undo log of your editor as they never see it. The same should be true of your private feature branch commits. They are squashed away never to be seen by human eyes again.

replies(1): >>42947194 #
4. jeroenhd ◴[] No.42947021[source]
When working together with other people using Git, I commit fast and often. My commit messages can be anything from "jdwqidqwd" to "add widget frubble() method" while I'm working. Sometimes repeated several times over, sometimes I remember to hit the "amend" checkbox. Basically, whenever I'm somewhat satisfied with the state of my program, I commit, finished or not. Everything in a nice, local, separate branch, pushed occasionally to make sure I don't lose any data.

And then when everything works, compress commits into a few big commits with squash, and actually try to merge that back into the main branch.

> I might start writing a new function, decide that I want it to be a class only to give up the class and wanting to return to my almost complete function.

For me, that would easily be three commits in my dev branch (one with a first implementation of the function, one with a refactor to a class, then another one back to a single function) and when the function is finished, one squashed commit in a merge request. If everything goes right, it's as if the class file was never there.

It has to be said, relying on squashing doesn't work well when you're working in a team that doesn't pay too close attention to merge requests (accidentally merging the many tiny commits). You also have to be careful not to squash over merges/use rebase wherever possible so your squashed commits don't become huge conflicts during merge trains.

When I work on my own stuff that I don't share, I don't bother squashing and just write tons of tiny commits. Half of them leave the code in a non-compiling state but I don't necessarily care, I use them as reference points before I try something that I'm not sure works.

There is something to be said for carefully picking commit points, though. While finding the source of a bug, git becomes incredibly powerful when you can work git bisect right, and for that you need a combination of granularity and precision. Every commit needs to have fully working code, but every commit should also only contain minimal changes. If you can find that balance, you can find the exact moment a bug was introduced in a program within minutes, even if that program is half a decade old. It rarely works perfectly, but when it does, it's a magical troubleshooting tool.

5. jaapz ◴[] No.42947194[source]
If I had 5 cents for every commit in a feature branch with the commit message "wip"...
replies(1): >>42949654 #
6. MrJohz ◴[] No.42948158[source]
I'm going to cheat and say I use a different VCS, but I do really like Jujutsu's approach here.

It has this idea of mutable commits, so essentially you can check out a commit, and then whenever you change a file, the commit is updated with the new file contents. Then internally, whenever a commit gets changed (or any aspect of the repository) that gets recorded in an append-only log. At any point in time, you can scroll through that log and restore any previous repository state, including changes to individual files.

By default, Jujutsu does the snapshotting thing (i.e. updating the commit with the contents of the local files) every time you run the `jj` command. However, you can set up file watchers so that it does the snapshotting every time a file changes in the repository. If you do this, you should be able to browse through the op log and see all of the changes you've made over time, including reverting to any of those stages when necessary.

In fairness, I've not tried the file watcher thing out personally, but being able to review the op log is fantastic for trying to go back to previous versions of your repository without having to do teeny-tiny "wip" commits manually all the time.

replies(1): >>42955098 #
7. foobarbaz33 ◴[] No.42949654{3}[source]
You should have 0 cents. Squash and chill is the way to go.
8. shandor ◴[] No.42955098[source]
Damn. Every time someone mentions Jujutsu I learn something awesome about it. I really need to give it a proper try one of these days.