Readit News logoReadit News
GuB-42 · 3 months ago
Why does it needs a new name?

I had a good idea of what it did before reading the article, it is a long name but not Java-long, and none of the suggestions so far are clear to me, even after reading the article.

The only somewhat confusing part is the "twice", because it can be more than twice. But if you think about it, if it has been changed more than twice, it had to be changed twice at some point, so it is not totally wrong.

mjd · 3 months ago
At the time I started writing the article, the utility was called `analyze-commits`. Hard to think of a worse name than that!

By the time I finished writing it I had come up with a less crappy name, but I thought I'd leave the question in the post anyway.

antonvs · 3 months ago
If you’re looking for something descriptive and not clever/catchy, I propose ‘find-repeat-changes’.
codewritero · 3 months ago
Jujutsu has a command which is helpful for this sort of workflow called absorb which pushes all changes from the current commit into the most recent commit which modified that file. (Each file may be merged into a different commit).
schrodinger · 3 months ago
This seems very similar to how I work by default. I sort of think in terms of "keyframes" and "frames", or "commits" and "fixes to commits."

Whenever I sit down to code with a purpose, I'll make a branch for that purpose: git checkout -b wip/[desc]

When I make changes that I think will be a "keyframe" commit, I use: git add . git commit -m "wip: desc of chunk" (like maybe "wip: readme")

if I make refinements, I'll do: git add . git commit --amend

and when I make a nee "keyframe commit": git commit -m "wip: [desc 2]"

and still amend fixes.

Occasionally I'll make a change that I know fixes something earlier (i.e. an earlier "keyframe" commit) but I won't remember it. I'll commit and then do: git add . git commit -m "fixup: wip desc, enough to describe which keyframe commit should be amended"

at the end I'll do a git rebase -i main and see something like:

123 wip: add readme (it's already had a number of amends made to it) 456 wip: add Makefile (also has had amendments) 789 wip: add server (ditto) 876 fixup: readme stuff 098 fixup: more readme 543 fixup: makefile

and I'll use git rebase -i to change it to reword for the good commits, and put the fixups right under the ones they edit. then i'll have a nice history to fast forward into main.

ZeroGravitas · 3 months ago
I think you might be aware given the specific words you use but for the benefit of others:

Git commit --fixup lets you attach new commits to previous hashes you specify and then can automatically (or semi-manually depending on settings) squash them in rebases.

koterpillar · 3 months ago
git-absorb (https://github.com/tummychow/git-absorb) does a bit more, figuring out the exact changes that should be fixed up.
globular-toast · 3 months ago
git-autofixup is better and easier to install: https://github.com/torbiak/git-autofixup
CorrectHorseBat · 3 months ago
JJ absorb does the same as far as I understand

Deleted Comment

metadat · 3 months ago
Yes, totally useful compared to default git base commands.

And also - melding the "changed twice" (or thrice...) mutations into a single commit is a brilliant isolation of a subtle common pattern.

goku12 · 3 months ago
git-absorb does exist [1]. It seems to be inspired by a mercurial subcommand of the same name. It's also available in most distro repos.

[1] https://github.com/tummychow/git-absorb

squeaky-clean · 3 months ago
"what-changed-twice" tells me exactly what the command does. "squash-what" tells me nothing, why is the program name asking me what to squash, and then why does it not squash? The only inaccuracy I can think of in the name is that it's technically "what-changed-more-than-once." But if something has changed thrice, by definition it's also been changed twice.
antonvs · 3 months ago
> “squash-what" tells me nothing, why is the program name asking me what to squash, and then why does it not squash?

‘squash-candidates’ would address all of that.

basemi · 3 months ago

   what-changed-once-more

eru · 3 months ago
> There's bonus information too. If a commit is not mentioned in the report, then it only changed files that didn't change in any other commit. That means that in a rebase, I can move that commit literally anywhere else in the sequence without creating a conflict. Only the commits in the report can cause conflicts if they are reordered.

This is only true in the textual level.

Semantically, re-shuffling commits like this can still cause conflicts. Ie it can break your tests. Not at the end, but for the intermediate commits.

_dark_matter_ · 3 months ago
This is why I no longer do atomic commits. I've just never had it be a benefit to walk through and guarantee that each commits tests and builds successfully. I so rarely back out changes that when I do, I test then that everything is working (and let's be honest, I back out usually at the PR level, not the commit).
mcintyre1994 · 3 months ago
The other benefit of this is the git bisect workflow. If you can’t build your intermediate commits then you likely can’t easily identify whether a bug was present on that commit (for many types of bug), and you therefore can’t identify the commit that introduced the bug.
globular-toast · 3 months ago
I often wonder what the point of using git at all is at this point. I suppose it's just your interface to the source repo, but a massively overly capable one. If you don't care about atomic commits then you might as well just do `git commit -a --amend --no-edit` periodically (you could even do it on every save). Then the reflog is your "undo" but you don't pollute the shared repo with shit commits.
eru · 3 months ago
If you want atomic commits, you need to set up your CI/CD to ensure that each intermediate commit builds and passes tests.

Most pull requests should probably be squashed to appear as a single commit in the final history. But you should have the option of leaving history intact, when you want that, and then your CI/CD should run the checks as above.

eru · 3 months ago
> I've just never had it be a benefit to walk through and guarantee that each commits tests and builds successfully.

If you never look at individual commits in your history, you might as well squash them.

mjd · 3 months ago
I agree. I decided years ago that that was a lot of work for little or no benefit.

It's enough for the tests to pass at each merge point.

gorgoiler · 3 months ago
Tools like this are also useful if you need to cherry pick a patch onto a release branch and want to know potential dependencies:

  ↑ newer
  D* fixes bug in crypto.py
  C
  B* rewrites crypto.sh in Python
  A
  0  last month’s release
  ↓ older
In this example, if the release needs the fix in D you’ll also need to cherry pick the rewrite in B.

You get false positives and false negatives: if B fixed a comment typo for example it’s not really a dependency, and if C updated a module imported in the new code in D you’d miss it. (For the latter, in Python at least, you can build an import DAG with ast. It’s a really useful module and is incredibly fast!)

So I would say the author’s tool is really multiple tools:

1/ build a dependency graph between commits based on file changes in a range of commits;

2/ automate the reordering and squashing of dependent commits on a private dev branch;

3/ automate cherry-picking commits onto a proposed release branch (which is basically the same as git-rebase -i); and

4/ build a dependency graph based on external analysis (in my example, Python module imports) rather than / as well as file changes.

Their use case is (1) and (2), (3) is a similar but slightly different tool to (2), and (4) is a language specific nicety that goes beyond the scope of simple git changes for, arguably, diminished returns.

MontagFTB · 3 months ago
I am familiar with an algorithm that stably brings a disjoint selection of items together around a specified point. Sounds similar to this case, where the disjoint selection are changes that happened to a given file.

The name of the algorithm is “gather”, by Sean Parent and Marshall Clow.

quuxplusone · 3 months ago
https://github.com/stlab/adobe_source_libraries/blob/7659244...

https://listarchives.boost.org/Archives/boost/2013/01/200366...

I gotta say, I don't see the greatness any more than most of the repliers in that Boost thread — it's just two stable_partitions in a row.

"[...] Or is there some optimization that gather provides over (stable_)partition? —— Nope. [...]"

MontagFTB · 3 months ago
The Boost thread starts with an example of how Bjarne replaced a bunch of complicated code with it.

It may be just two stable partitions, but “just” is doing a lot of work there. The algorithm becomes obvious once someone has identified it.

JKCalhoun · 3 months ago
"muster" comes to mind and is different than "gather".
zahlman · 3 months ago
When I make Bash aliases or functions for Git functionality, I always name them as `git-something-or-other`. That way they're namespaced in a way that I find pleasant both for tab completion and for easy of memory. I think that should apply to more complex utilities, too.

By my usual naming conventions, this one would be `git-repeatedly-changed`.

nothrabannosir · 3 months ago
Last but decidedly not least: if you have `git-foo` on the PATH, you can do `git foo` and it will automatically pick up your program.

If I remember early git days correctly, that's how git was implemented: a bunch of separate utilities working together on the database which is the .git folder.

gavmor · 3 months ago
These are called alternative "porcelains:"[0] third-party, user-friendly interfaces built on top of Git's stable, low-level plumbing commands.

0. https://git-scm.com/docs/git.html#_low_level_commands_plumbi...

mjd · 3 months ago
I usually do that too, but this seemed to me like it's not really a git utility. It's just a filter.

I can see the argument in favor of `git-` also.

But I think I'd prefer `git-changed-twice` to be a wrapper that takes a reflist argument, and runs `git-log --stat reflist | what-changed-twice`.

handsclean · 3 months ago
I suggest group-commits-by-file , group-commits , or group-by-file, depending on whether you want it to make sense out of context and whether you ever group commits differently. You might then feel compelled to add a final line like “… and 12 files with 1 commit each”, or even to enumerate them, which sounds like it’d be useful anyway. “what” isn’t doing any work, there’s already an implicit “what” in the call-response paradigm. “Changed” implies you’re detecting changes, but you’re not, you’re operating on a data structure that happens to represent changes.