Hacker News new | ask | show | jobs
by lostmsu 71 days ago
How is this different from branches?
4 comments

They aren't really. It's basically like getting an auto generated ref/branch name for each new commit, with convenience rewriting every ref when you rebase.

It's a bit more convenient if you prefer referring to a non-leaf commit directly rather than relative to the leaf branch a la master~2

change ids are more analogous to commit messages than branches, eg suppose that in a feature branch you have a "Delete deprecated classes" commit; in git there is a clear idea of "cloning" this commit (eg rebase, cherrypicks, maybe reverts) and the common sense that the new commit inherits the same commit message. Change ids are the same thing but in hex id form that can be created for every new commit/stash/index.

They allow for example to identify all the clones of a commit and they allow to give stable identities across rebases eg suppose you rebase a typo at the beginning of a feature branch without change ids a reviewer sees n new unrelated commits while with change ids it is possible to clearly identify which commits where changed/added/removed since the previous review iteration.

> suppose you rebase a typo at the beginning of a feature branch without change ids a reviewer sees n new unrelated commits while with change ids it is possible to clearly identify which commits where changed/added/removed since the previous review iteration.

A rebase can introduce change to a commit in cases such as handling conflicts or squashing.

Also, a commit already retains it's commit message after rebasing.

> A rebase can introduce change to a commit in cases such as handling conflicts or squashing.

and with change ids you can quickly separate commits that changed from commit that did not.

> Also, a commit already retains it's commit message after rebasing.

but commit message are not ids, there is no command for checking out a commit by its message, nor any sense that commit with the same message are somehow functionally related

You amend or rebase a commit and can still reference it by the same name.
A branch is mutable and holds only one version of history at a time.

If you never rewrite history, you could achieve something similar, but it precludes you from having a “tidy” branch.

Whether or not you’re into rewriting history is a different discussion that has been hashed out over and over again.

Another thing that becomes easier with change IDs is reviewing multiple related commits together, essentially "stacked pull requests".

If you treat a branch as your unit of review, then it becomes super difficult for someone to submit a chain of related changes. You'll be constantly rebasing your pull requests onto each other as you get feedback from dependent branches.

I heard that the github CLI recently introduced support for this, but since in git there's no concept of dependent branches (a branch isn't even an object in git, just a reference to a commit), I think this approach will always be clunkier than reviewing commits related by a change ID.

> Another thing that becomes easier with change IDs is reviewing multiple related commits together, essentially "stacked pull requests".

What's wrong with branches?

> If you treat a branch as your unit of review, then it becomes super difficult for someone to submit a chain of related changes. You'll be constantly rebasing your pull requests onto each other as you get feedback from dependent branches.