Live data from Hacker News

Git Notes: Git's coolest, most unloved­ feature (2022)

tylercipriani.com

71–80 of 147 posts

Re: Git Notes: Git's coolest, most unloved­ feature (2022)

#71
post #5

Git notes are only cool if you frequently add text to a commit after the commit has happened and visible to others. The Acked-By and mailing list discussion link examples don't seem to be good examples. Both of these are likely already known when the commit is made. And git commit message basically can have an unlimited length, so you could very well copy all the discussions about the commit that happened on a forge…

The common failure mode is commit messages proudly proclaiming they fixed a bug that they did not. And linking knock-on bugs created by their fixes to one bug.

Maybe I’m weird that way. I’ve had too many coworkers who don’t really even look at annotations to remind themselves why this code was written in the first place. They will just yolo and hope nobody ties the problems back to them. But once you’ve dealt with an irate customer who waited impatiently for a bug to be fixed, and only to have the bug be reintroduced a short time later, you may become more circumspect about bug fixes.

There’s often a refactor needed to fix multiple bugs at once. There’s often refactor can open up new feature opportunities, or performance improvements.

Re: Git Notes: Git's coolest, most unloved­ feature (2022)

#72

There are many "Git's coolest, most unloved feature", e.g.: bisect, pickaxe, reflog, range-diff, archive, annotated tags, etc. Sadly they are often forgotten as many people thing of Git only as a glorified Google Drive...

Ha, I expected to know the features you were going to list, but got surprise attacked by pickaxe. What the hell? I guess I shouldn’t be so confident

Re: Git Notes: Git's coolest, most unloved­ feature (2022)

#73
post #24
post #5

Git notes are only cool if you frequently add text to a commit after the commit has happened and visible to others. The Acked-By and mailing list discussion link examples don't seem to be good examples. Both of these are likely already known when the commit is made. And git commit message basically can have an unlimited length, so you could very well copy all the discussions about the commit that happened on a forge…

> The Acked-By and mailing list discussion link examples don't seem to be good examples. Both of these are likely already known when the commit is made. Discussion regarding a commit (is: review) and acknowledgment of a commit cannot happen before the commit has been made. > One use case I think might be a better example is to add a git note to a commit that has later been reverted. Commit messages are better for thi…

You’re treating a commit as an atom, which is not true in patch based git situations like Linux.

Most of the rest of us do not work this way, but they still do. The rest of us also only have to deal with three way merges most of the time, instead of octopus merges. Though I jokingly call, “fixing an incorrect three way merge” a “five way merge” because you end up doing a star shaped pattern of diffs to re-resolve the code to retain the intents of all three versions. A to merge, B to merge, merge to HEAD~, A to HEAD~ and B to HEAD~

Re: Git Notes: Git's coolest, most unloved­ feature (2022)

#74
post #36
post #29

Earlier quoted context omitted.

> Discussion regarding a commit (is: review) and acknowledgment of a commit cannot happen before the commit has been made. It can't happen before the commit on a feature branch, but it can happen before merging the commit back to the main development branch. Given that a rebase or merge commit is already frequently necessary to integrate changes from a feature branch after review is finished, I don't see why this typ…

The history-destroying problems of rebasing are a rant on their own.

Can you say more? I use rebase to avoid history destruction/obscuration. Do you mean squash? If so then I agree.

Re: Git Notes: Git's coolest, most unloved­ feature (2022)

#75

Another little-known feature is git trailers: https://alchemists.io/articles/git_trailers These are key-value structures data that can be included on a commit when it is created. These are used by some systems for attaching metadata. For example, Gerrit uses this for attaching its Change-Id.

One more similar feature from a different system: PostgreSQL COMMENT https://www.postgresql.org/docs/17/sql-comment.html This allows you to attach text to various database objects in PostgreSQL. I wish PostgreSQL had a feature that was more like structured key-value database object metadata that could be edited.

It's a great feature, but GitHub's parser chokes on it.

Compare:

https://github.com/jchester/spc-kit/blob/eb2de71d815b0057e20...

To:

https://github.com/jchester/spc-kit/blob/main/sql/02-spc-int...

Basically the original rendering makes me look incompetent to a casual skimmer. Plus tools like JetBrains IDEs can suss out what comments belong to what DDL anyway.

Re: Git Notes: Git's coolest, most unloved­ feature (2022)

#78
This is great! And how did I not know about this? My favorite days are when I learn something new. Even better are when I learn that I was wrong and change my mind to improve my thinking. So meta!

Git notes would be ideal for annotating commits that contain commit hashes used as breadcrumbs to inform the developer (usually me months later) about context around previous work. These hashes might have changed due to a rebase or from using disk space optimization tools that rewrite history like these:

https://rtyley.github.io/bfg-repo-cleaner/

https://github.com/rtyley/bfg-repo-cleaner

https://github.com/newren/git-filter-repo

https://github.com/tiavision/GitRewrite

See also:

https://stackoverflow.com/questions/5613345/how-to-shrink-th...

https://stackoverflow.com/questions/1398919/make-git-consume...

https://stackoverflow.com/questions/2116778/reduce-git-repos...

https://stackoverflow.com/questions/3119850/is-there-a-way-t...

https://stackoverflow.com/questions/38789265/git-delete-some...

https://stackoverflow.com/questions/16057391/git-free-disk-s...

https://stackoverflow.com/questions/31423525/how-to-reduce-d...

https://stackoverflow.com/questions/16854425/compact-reposit...

https://stackoverflow.com/questions/13999191/trimming-huge-g...

https://stackoverflow.com/questions/4515580/how-do-i-remove-...

These methods are all uniquely terrible in various ways. Most likely user error on my part. I need this technique:

1. Choose a range of commit hashes (or hashes before a commit) and remove them. This can be useful when splitting repos, for example on projects that started as backend+frontend where the frontend is being forked off in a new repo and the older backend portion needs to be removed from it for security/privacy.

2. Rebase all branches (including those that crossed the deleted portion) to preserve their structure but start/end as recently as possible. Optionally discard branches that were created and merged entirely within the deleted ported, unless they're the trunk of other branches that merge after the deleted portion.

3. Search for old commit hashes in commit messages and update them to the new hashes while rebasing.

4. Bonus points for updating stashes (or other git features) having any commit hashes in their names. Also for importing/exporting a list of important commit hashes for use in project management, such as updating hashes in comments on kanban boards like Jira.

5. More bonus points for searching for large files (such as app.js or other build artifacts) so that they can be stripped from commits in branches, preferably not on a main trunk like master.

If you followed this far, I could also use a technique that rebases merged branches so that they form a series of D shapes instead of overlapping B shapes (this is useful during git bisect). Ideally this would happen automatically or be enforced via rules on sites like GitHub and GitLab. I always rebase my branches before merging, but others can't be bothered.

https://www.atlassian.com/git/tutorials/merging-vs-rebasing

Where I'm going with this: I git reset and git cherry-pick constantly in my own branches before merging, so that each branch has a clean work history like the trunk. I think of this as quantum committing, because I keep exploring the problem space until I find a solution that collapses (merges) into the history.

The problem is that git GUIs are inadequate for this work. I need to be able to cut/copy/paste commits, drag and drop them for reordering, etc. It should also derive the commit diff needed to make a commit match a branch (or folder) rather than throwing a conflict in my face, so that it operates more like Apple's Time Machine. If I had this app, I could simply select all commits that I wanted to delete, it would ask me "this rewrites history, are you sure?", and then delete them and do the right thing for affected branches. It would also have infinite undo powered by git reflog.

The idea being that commit hashes should not take priority - it's all about the information. We should never be trapped by the state of the repo, because that creates anxiety.

So we're missing a tool to orchestrate git the way that Kubernetes orchestrates Docker.

Re: Git Notes: Git's coolest, most unloved­ feature (2022)

#79

There are many "Git's coolest, most unloved feature", e.g.: bisect, pickaxe, reflog, range-diff, archive, annotated tags, etc. Sadly they are often forgotten as many people thing of Git only as a glorified Google Drive...

Git notes is redundant since you need a higher-level project management tool to track features anyway. Roadmaps, feature hierarchy and non-technical details. Think of any big tracker or Jira. I think that's fine. Unix philosophy is to focus on one thing and do that well.

A project management tool that uses Notes would make IDE integration easier though.

I vaguely recall dismissing Notes as a solution to my problems. I may be recollecting some of this wrong, but IIRC the problem with Notes is that they aren’t batteries included. It’s easier to cajole devs into using new tools if the setup is simple and it doesn’t complicate their workflow. Notes fails this litmus test. Set it on by default and make it come down with pull and up with push instead of a separate activity.

Re: Git Notes: Git's coolest, most unloved­ feature (2022)

#80

Another little-known feature is git trailers: https://alchemists.io/articles/git_trailers These are key-value structures data that can be included on a commit when it is created. These are used by some systems for attaching metadata. For example, Gerrit uses this for attaching its Change-Id.

One more similar feature from a different system: PostgreSQL COMMENT https://www.postgresql.org/docs/17/sql-comment.html This allows you to attach text to various database objects in PostgreSQL. I wish PostgreSQL had a feature that was more like structured key-value database object metadata that could be edited.

I love PostgreSQL content. I once used them in a commercial product where table and column comments would contain metadata. The product is now dead. I took this event as a cautionary tale that when we feel super empowered as developers, we often miss the market.
Post reply on HN