Remix.run Logo
Highlights from Git 2.54(github.blog)
130 points by ingve 3 days ago | 74 comments
ajoberstar 3 days ago | parent | next [-]

Nice to see some seemingly jujutsu inspired features getting into Git core.

  git history reword ~= jj describe

  git history split ~= jj split
https://git-scm.com/docs/git-history

https://www.jj-vcs.dev/latest/cli-reference/#jj-describe

https://www.jj-vcs.dev/latest/cli-reference/#jj-split

NewsaHackO 2 hours ago | parent | next [-]

jj is a "unofficial" Google project that one has to sign a Google CLA to contribute to. I don't think it would be a good idea to trust/transition to a system like that from git.

baq an hour ago | parent [-]

what has one to do with the other...?

codygman 9 minutes ago | parent [-]

I'll consider avoiding jj because of this, personally.

aulin 6 hours ago | parent | prev | next [-]

Not familiar with jj and don't want to get into bike shedding, but how is describe supposed to be a good name for history rewrites?

roblabla 6 hours ago | parent | next [-]

jj describe gives a name to a commit. In jj, everything rewrites the history, so there's no real point in calling it out in the command name since it's just the default behavior.

locknitpicker 2 hours ago | parent [-]

> In jj, everything rewrites the history (...)

Surely that isn't true, otherwise it would be completely unusable for auditing.

kps 31 minutes ago | parent | next [-]

It's not true, in that sense. Commits in jj are basically the same as commits in git as far as mutability is concerned. But in jj you normally work with changes, rather than commits, and open changes are mutable (by altering which immutable commit they point to in the backing store). And there is effectively an append-only audit trail of these alterations (which is what makes `jj undo`/`jj redo` simple).

Some comments here are confusing the issue by saying ‘commit’ when they mean ‘change’ in the jj sense.

baq an hour ago | parent | prev | next [-]

it is true. some history is marked immutable by default; in git, everything is mutable by default and you have to add branch protection on the server side. (granted, you can change what is immutable in jj relatively easily, so you shouldn't ignore branch protection if you're using jj exclusively with a git repo, either.)

BeetleB 17 minutes ago | parent | prev [-]

By default, if you push to main/master, it marks those commits as immutable (you can still force change). You can configure this to other branches.

But ... is it really that different from git? You can always rewrite history in git, correct?

auscompgeek 5 hours ago | parent | prev | next [-]

describe is also the command you can use to edit the commit message of the change you're currently drafting. In jj there's no staging area, every modification to the working tree immediately gets integrated into the current commit. (This means if you have no diff in your working tree, you're actually on an empty commit.)

baq 4 hours ago | parent | prev | next [-]

in jj the history has mutable and immutable commits.

skydhash 5 hours ago | parent | prev [-]

Not really familiar too, but jj has everything committed by default (no index, staging area, and uncommitted changes). You use ‘jj new’ to stop adding changes to the current commit.

‘jj describe’ lets you add a message to a commit as it’s not there by default.

chrishill89 2 hours ago | parent | prev | next [-]

Yeah it’s a direct inspiration.

wakawaka28 4 hours ago | parent | prev [-]

If this is meant to be a dig, you should keep in mind how much jj owes to git.

ambicapter 2 hours ago | parent | next [-]

Doesn't have to be a dig. One of the great things about having alternatives is that they can learn from each other.

baq an hour ago | parent | prev | next [-]

and now git owes jj a couple ergonomic improvements. this is a net win for both.

wakawaka28 17 minutes ago | parent [-]

I think this is cluttering git with a bunch of special-case commands when rebase is all you need. Next thing you know, people will say we need to drop git because there are 5 ways to do everything.

IshKebab 4 hours ago | parent | prev [-]

I don't know if it was meant to be a dig but I hope you don't think the fact that Git was a big advancement on SVN means it doesn't deserve any criticism.

It's very widely remarked that the Git CLI is pretty miserable, and as soon as a better (so I hear) alternative comes along they suddenly realise and start improving it... This happens all the time in software.

Some software has crap UX or missing obvious features (e.g. comments in package.json). People try and improve it but are rebuffed because the maintainers claim it's fine as it is. Effort goes elsewhere to a competitor project which starts to attract users. Maintains of the original project have a sudden and coincidental change of heart!

chrishill89 an hour ago | parent | next [-]

> It's very widely remarked that the Git CLI is pretty miserable, and as soon as a better (so I hear) alternative comes along they suddenly realise and start improving it... This happens all the time in software.

This command is implemented by just one single (but prolific) contributor. His own idea.

wakawaka28 20 minutes ago | parent | prev | next [-]

>It's very widely remarked that the Git CLI is pretty miserable, and as soon as a better (so I hear) alternative comes along they suddenly realise and start improving it... This happens all the time in software.

I don't think these claims have merit, for the most part. More often than not, people just don't take any time to learn git, then get on a soapbox about it.

If you think these commands are worthwhile, by all means use them. I happen to think git rebase is all you need. Giving people crutches to avoid using it just delays their enlightenment. But not everyone reaches enlightenment, it's true.

I don't think jj adds anything compelling over git either. But different strokes for different folks...

locknitpicker an hour ago | parent | prev [-]

> It's very widely remarked that the Git CLI is pretty miserable, (...)

You hear some very vocal critics expressing hyperbolic personal opinions on the topic, but I find that in the majority of the cases the opinions aren't objective or grounded on reality. It's just people whining.

The litmus test is asking what is the worst example of this "pretty miserable" CLI they talk about. More often than not it's just baseless nitpicking. I recommend you give the litmus test a try to see how far this myth flies.

ufo 6 hours ago | parent | prev | next [-]

I have always had this problem with hooks and new contributors: since hooks don't run by default if you just clone the repository, my open source projects get many PRs from new contributors that did not run the linting and commit hooks. I understand there's a security reason for this but what workflows have worked best for you to get everyone to run the hooks? And do you think the new config-based hooks can help new contributors?

NekkoDroid an hour ago | parent | next [-]

I wish that git would auto check for a `.githooks` directory in the repo root and prompt on first clone if the `core.hooksPath` should be changed for this repositry and when pulling any tracked file in hooksPath causes a warning (though this still leaves out the case that some hook just invokes a script in the repo outside the dir).

sethops1 6 hours ago | parent | prev | next [-]

> what workflows have worked best for you to get everyone to run the hooks

By running the linters and any other checks on CI instead.

jayd16 3 hours ago | parent | next [-]

Why waste a round trip, build time, loss of flow and CI machine queue wait time when you can catch things early?

CI should also run all the checks but CI checks are not a replacement for local hooks. LFS and things like it can't be implemented as remote CI checks.

Why are we acting like a James Bond villain, slowly lowering the changes into the vat of sharks after we've left the room? I want the hooks. Can we talk about making that easy, assuming some people want them?

n_e 2 hours ago | parent | next [-]

> Why waste a round trip, build time, loss of flow and CI machine queue wait time when you can catch things early?

Because we want to be sure that the checks have passed, and that they have passed in a clean environment.

Contributors can, in addition, use git hooks, or run tests in watch mode, or use their IDE.

Also it's annoying to have slow git hooks if you commit often.

crote an hour ago | parent | prev | next [-]

You're looking for a technological solution for a human problem.

Automatically running arbitrary code from random repositories is a Really Bad Idea, so Git will almost certainly never auto-install pre-commit hooks. Just mention it in the README and run a checker in CI to confirm they are using it, it really isn't that difficult.

People wasting 2 minutes of their own time once during their first contribution because they didn't read the README is not that big of a deal. What's next, you want a script to automatically sign a project's legally-binding CLA on checkout?

jayd16 an hour ago | parent [-]

You're talking out of both sides of your face here. It's dangerous and also it's super easy and you should do it first thing without having to think because it's so easy. You shouldn't run this code but also the build machine automatically runs it.

We already know we're definitely going to run some of these. We know we want to maintain changes to these hooks. Can we stop pretending like we're not doing that? We get it. Some of these will be untrusted so let's design a system to handle that instead of not designing a system and deciding to be just short of as unsafe as possible.

Automation an uniformity increases safety. Human intervention increases human error. Its just a matter of actually finding a good solution to know what is trusted but instead we get "just set it up manually because its safer."

krzyk 25 minutes ago | parent | prev [-]

Local hooks are just a convenience. CI checks are assurances, you have to have them.

If one hates the round-trip he/she will adopt hooks quickly.

jayd16 11 minutes ago | parent [-]

LFS hooks are not just a convenience, for example. CI, despite being a useful thing in its own right, is not a replacement.

baq 6 hours ago | parent | prev | next [-]

autoformatter and autofix linter results can be committed and pushed by CI into the PR branch itself. this is a pain sometimes, but as a repo owner it should protect your sanity.

sgarland 4 hours ago | parent | next [-]

Yep. Nothing I hate more than some trivial formatting error that could easily fix itself halting CI. I am all for consistent formatting and linting, I just think it should be silently handled without fuss.

skydhash 5 hours ago | parent | prev [-]

I just add a check workflow that test that the files are well formatted and linted. If it passes, one of the key things I check are changes to the configuration. Some tools allows for bypass comments, so I keep an eye out for those too.

ufo 5 hours ago | parent | prev | next [-]

We do run the linter on CI as well, but I think our comitters would get faster feedback if they ran those checks locally.

lou1306 5 hours ago | parent | next [-]

Well you can tell them to please enable hooks in the PR guidelines, but you cannot really police what they do or don't run on their own machines.

jayd16 2 hours ago | parent [-]

This is very much not a serious solution. Look at the case of LFS.

LFS needs an install step and it needed to be brought into git itself to cut through all of the problems. Manually managing hooks is not sufficient.

No amount of "please don't fuck it up" in the readme is going to save you.

Even CI checks for what should and shouldn't look like an lfs stub is non-trivial. I don't think such a thing even exists today.

lou1306 2 hours ago | parent [-]

The alternative is have hooks _forcibly_ run on people's machines, which is fantastic as an attack vector and CVE generator but probably not a good choice in other respects.

jayd16 2 hours ago | parent [-]

No there are a million miles in-between no support/Don't use it and arbitrary code execution.

Signed git plugins and manifest or a canonical way to define hooks in repo that most tools can interface with and allow the user to automatically set up but asks to do so or really so much more.

I don't know why people get fixated on this as if 99.999% of what git pulls down isn't code you expect to run and there are systems in place to protect that.

esafak 4 hours ago | parent | prev [-]

You can issue installation instructions on linter failure in CI.

IshKebab 5 hours ago | parent | prev | next [-]

As well, not instead. Just add `pre-commit run -a` to your CI. Job done.

It's still annoying for new contributors though because they might not know how to set up pre-commit (which was quite a pain until recently because it's written in Python).

Flimm 5 hours ago | parent [-]

To clear up any confusion, Git runs pre-commit hooks, and they can be written in any programming language. There's a completely separate and independent project that gave itself the confusing "pre-commit" name, and it is written in Python. This project aims to make it easier to configure pre-commit hooks. An alternative to it is "prek", written in Rust.

sgarland 4 hours ago | parent [-]

Yes, and I hate it so, so much, and frankly don’t get the appeal. You want one-click installation of hooks? Bundle a shell script called run_first.sh that symlinks the hooks into .git.

jayd16 6 minutes ago | parent | next [-]

That doesn't automate the maintenance of the hooks, doesn't handle cross branch differences, opens you up to all kinds of security holes because now it'll just do whatever the hook points to which is likely to be in the repo and not in some special higher scrutiny flow...

All the push back to making this system good just ensures its as terrible as the nay-sayers fear.

IshKebab 4 hours ago | parent | prev [-]

The pre-commit tool does way more than that. For example the clang-format hook will download and run a specific version of clang-format.

locknitpicker an hour ago | parent | prev [-]

> By running the linters and any other checks on CI instead.

Running linters on CI is an antipattern if there was ever one. That and configuring pipeline runs to fail for linting issues.

Sometimes some people just want to create their own problems. Configuring the editor solves most of the problems, and hooks add a failsafe. Once the code is committed, it should be immutable.

jbverschoor 4 hours ago | parent | prev | next [-]

I don't want you to run arbitrary hooks on my machine. As with CI/CD... your hooks should simply point to a script instead

jayd16 4 hours ago | parent [-]

Ok well what about when I pay you and give you a local machine to work on?

Can I pay you to run hooks on the work machine I own because it saves a lot of work on the share build machines? Can we talk about making that situation less error prone?

numbsafari 2 hours ago | parent | next [-]

Tools growing unexpected code execution is how we keep having problems with secrets and other important things being stolen. If you add this feature to git, generally, then anybody cloning a git repo is going to have to deal with the fact that `git clone` might run arbitrary code. `git clone` is like `cp`. Do you want `cp` to unexpectedly run code? It should never do that.

Why force git to be a build tool?

Just document how to execute the scripts/checks that will be used by ci. Provide a simple script in the repo that folks can intentionally execute.

jayd16 2 hours ago | parent [-]

Git is already a build tool and LFS is a great example of something git should be able to do and is also an example of how bolted on these things feel because of pointless push back in talking about a real solution.

You don't need to bring up bad ideas as if it precludes the existence of good ideas. Let's talk about good ways to solve these problems and improve the tool.

jbverschoor an hour ago | parent | prev [-]

Yes that’s perfectly fine of course. But these days that’s not so common

jayd16 3 hours ago | parent | prev | next [-]

Adding configuration to the config makes things feel far less exotic. I think these changes certainly improve things, but there's still plenty of room to go further.

I think there should probably be a way to specify canonical git configuration for things like hooks and LFS and all of that. It would be nice if when you clone, git prompts you to trust the remote config or to ask you to accept each new change as they come or fully reject them.

Having to scrape through the readme of every repo and then run arbitrary scripts doesn't seem like the most secure solution. When there's a canonical flow gitlab GitHub and all the tooling can support it and have proper permissions around it.

It's really disappointing how much lack of empathy there is when talking about new git features. Forget empathy. There's outright disdain for discussing alternative workflows.

purerandomness 5 hours ago | parent | prev | next [-]

In PHP, an established tool is adding GrumPHP [0] to your dependencies.

It will then handle git hooks on each commit via composer script by default (but can be omitted per commit).

[0] https://github.com/phpro/grumphp

Sol- 3 hours ago | parent | prev | next [-]

I always considered hooks a nice to have feature for devs to already validate that their PRs will probably satisfy certain CI checks. If they don't install or run them for whatever reason, it's on them to do another iteration and update the code to make it mergeable if CI complains. So I usually considered it fine that they are only opt-in, since the merge will be gated by a CI outside of the dev's control anyway.

scq 5 hours ago | parent | prev | next [-]

The approach some JS projects have taken is to use Husky, which automatically sets up the git hooks when you install the project's dependencies during development.

sestep 5 hours ago | parent | prev | next [-]

I agree with the other replies saying to just run the checks in CI and have the CI error message mention how to install the pre-commit hook.

I'm glad cloning a repo doesn't automatically install hooks since I strongly dislike them: I often use Git commands in the terminal but sometimes I use the VS Code UI to commit, and it's extremely frustrating when simply creating a commit runs for several seconds because of some pre-commit hook.

sgarland 4 hours ago | parent [-]

There’s almost certainly a way to make VS Code use --no-verify.

XorNot 5 hours ago | parent | prev | next [-]

I add an autogen.sh script to all my repositories that does things like this as it's first action.

misnome 4 hours ago | parent [-]

You can also set up a central git template repository, so hooks get automatically added into every repository you clone

1718627440 5 hours ago | parent | prev [-]

My project needs other things on setup as well, so I just have a setup script in my repo. `mv hooks/foo .git/hooks` is then just yet another step.

the_duke an hour ago | parent | prev | next [-]

Config based hooks seem to miss the mark though?

The per-repo config is in `.git/config`, so that can still not be checked into the repo itself, unless I'm missing something?

So not very useful at all...

I get the security implications, but there could be a checked in `$REPO/.githooks`, and a prompt asking to allow running those hooks , with an approval marker being stored inside `.git/`.

optionalsquid an hour ago | parent | prev | next [-]

Support for config based hooks is very nice.

Only a few days ago, I was just looking for some way to automatically check (and fail) if there are inactive hooks when I try to commit. I already use `advice.ignoredhook`, but it's easy to miss the warning if you commit through VSCode, and possibly through other IDEs.

With this, I can just write a simple script to perform that check, and add it to my global config

charles_f 3 hours ago | parent | prev | next [-]

git history makes me think of git revise^1, which gives you a bunch of handy tools to changes your history, move commits around, remove some of them, cut them (which git history now does). I found it very handy in the past

1: https://git-revise.readthedocs.io/en/latest/man.html

WhyNotHugo 5 hours ago | parent | prev | next [-]

The new additions to `git add -p` seem pretty neat. Staging changes with `-p` is seriously underrated!

jinushaun 5 hours ago | parent | prev | next [-]

`git history reword` is great. Using `git rebase -i` just to fix a spelling error is overkill and doesn’t actually do what I want.

jauntywundrkind 3 hours ago | parent [-]

Why doesn't it do what you what?

I hate to be the worry wart, but I am worried folks are going to avoid `git rebase -i` even more now. It is such an excellent excellent UI in my opinion: it shows you the history of what is clearly, and let's you modify it as you please!

NekkoDroid an hour ago | parent [-]

> Why doesn't it do what you what?

If you have anything else branching/referencing a commit after the reword commit that isn't part of the branch you are rebasing you now have all those references still pointing to the old commit and need to go through every one of them to fix them.

everybodyknows 2 hours ago | parent | prev | next [-]

> ... rewrites any descendent branches to point at the updated history.

But what about local heads referred to only by a "soft" tag? Is their history rewritten, or is it left to refer to the old history?

greg_dc 4 hours ago | parent | prev | next [-]

Those new git history commands will save me an average of maybe a minute a day, but it's still definitely handy nonetheless! After 2 months, that's an hour back!

The git log -L change is nice to see as well. Anything that makes git more filterable gets my vote.

samtrack2019 3 days ago | parent | prev | next [-]

the new git history command seems to be useful for quick reword, altho since i use lazygit/magit i don't really see much of a problem to me

olejorgenb 6 hours ago | parent [-]

Wish reword took a commit range though

yencabulator 3 hours ago | parent [-]

I had to check and `jj describe` does. You get all the commit messages in a single file to edit, with headers separating them.

Rover222 4 hours ago | parent | prev [-]

I do almost no direct git work myself these days. Using claude in Conductor. Working on a team. I'll tell claude what do do in git sometimes, but there doesn't seem to be much need to do it myself anymore, even with complicated rebases, reflogs, etc.

ramon156 3 hours ago | parent [-]

I'd advise to do what you're doing, but to check the commands it runs and figuring out why it does these things. The first step is usally "what does git [command] do?" followed by `man git-[command]` and see what it does.

That way you're still "blazingly-fast with your SOTA-LLM!!!" while also understanding why :)