5 ms·
Wish `git` didn't have annoying special cases in it. For instance git rebase -i HEAD~2 won't work if there are only two commits, because HEAD~2 refers to a
by kazinator 12y ago
Wish `git` didn't have annoying special cases in it. For instance
git rebase -i HEAD~2
won't work if there are only two commits, because HEAD~2 refers to a nonexistent commit after the first two.
There should be some friggin' NIL terminator there which takes the HEAD~2 reference.
Imagine having a function to, say, delete characters from a string which takes an open-ended range [from, to). Then imagine that the index to has to exist in the string; it must not point one element past the end! Oops, you cannot delete from a position to the end of the string.
The garbage-collected object graph is nice and "Lisp-like" in some ways, but silly in others.
Oh, and in case you're thinking "just make an empty initial commit, and it will effectively be your NIL terminator". No can do; git doesn't allow empty commits. Of course, you can make a file called ".nil" and add it and commit. Use "()" as the commit comment. :)
- chx 12y agogit commit --allow-empty
- kazinator 12y agoThanks; that is perfect. I just tried that it works on the root commit in a newly initialized repo. I will always do this from now on: $ git init $ git commit --allow-empty -m NIL Maybe the git maintainers can be persuaded to make a "git init --nil" which does this in one step.
- mitchty 12y agoEh, just make an alias in ~/.gitconfig no need to add more options to git. That is: [alias] nilinit = !sh -c 'git init && git commit --allow-empty -m NIL' And now git nilinit does what you want.
- kazinator 12y agoThe problem is that what I want is for "git init --nil" to do that, not for some "git nilinit". Actually, I want "git init" to do that by default! Every git repo should begin with an empty commit. In fact, there should be a special SHA built in representing the empty commit; perhaps an all-zero SHA. This object is understood not to occupy any space in the object store beyond its own SHA: you don't look for an all zero SHA in the object space; it just stands for itself. Then this same can be used as a parent in any orphan branch. One of the benefits is that this zero SHA is global. And so all git repos have a common ancestor automatically. If you and I take some code tarball (the same one) and start git repos individually, then we implicitly have a common merge-base: the NIL commit. If I pull from your repo, then we have this: your-import <--- your-hacks / NIL \ my-import <--- my-hacks your-import and my-import are the same since we imported the same thing. I can just do a "git rebase your-hacks-branch" to transplant my-hacks over your-hacks, implicitly using NIL as the merge-base.
- mitchty 12y agogit-subtree already allows for embedding one git repo in another. https://github.com/git/git/blob/master/contrib/subtree/git-subtree.txt https://github.com/git/git/blob/master/contrib/subtree/git-s... I see the point but not sure I agree that we should treat all git repositories as having a common base commit. Not thought it through however.
- stormbrew 12y agoI actually put a basic description of what I intend to do with the repo in the message of my empty root commit these days. Helpful for remembering if I lose momentum and come back to it later. I'd actually love to start doing that with starting a new branch, but I use rebase -i too much and it really really dislikes empty commits in the set you're working on (it just throws them out).
- nshepperd 12y agoI feel like the lack of an initial empty commit is really a failure to match the intuitive graph model. Clearly there should be an arrow corresponding to "adding the first files". And that arrow needs somewhere to go from and to. Hence, `git init` should always start by creating an initial commit object referring to an empty tree. A side bonus of this would be that since the initial commit is empty it has a fixed id. Suddenly, all git repositories have a common ancestor, and you can merge any two random projects together without losing history!
- kazinator 12y agoI echoed this exact idea in another comment in the thread, right down to that commit having a fixed ID. (I proposed the all-zero SHA (which is not really a SHA)).