by patrec · 5y ago · 0 comments
What's more troubling is that git can't do some very basic stuff well, like merging branches. I mean you can do the merge, but good luck trying to revert it[+] or trying to get git to deal intelligently with non-linear history in general.
Another fun thing is that every git repo starts its life with an off-by-one error: there is no canonical (and identical) first "root" commit, a NIL commit if you will. This is unfortunate for two reasons:
1. A lot of common scripting idioms will break on the first actual commit (e.g. finding changed files via git diff --name-only A A^ will not work if A is the first commit; yes it's possible to work around that, just like you can write shell scripts that deal with filenames with spaces). Also, it would be convenient in many cases to have an canonical initial empty NIL commit as symbolic reference, similar to how having HEAD is handy.
2. More subtle: the fact that there is no common shared root commit between arbitrary repos makes a couple of things more involved and confusing than they would otherwise be, for example rewriting several different repos into one after the fact.
In theory it would be possible to work around that by everyone agreeing on a canonical first commit to start each repo with, but in practice that's of course unlikely to happen.
Lastly, and not entirely unrelated: many, but no good solutions for sub-repositories.
[+] https://github.com/git/git/blob/master/Documentation/howto/r...
IME Git handles non-linear history pretty well. AFAICT any DVCS will inherently have the same problem; you can't necessarily memory-hole the fact that the merge has happened because other people may already have your merge. What are you claiming is the "right" way to handle that case?
> In theory it would be possible to work around that by everyone agreeing on a canonical first commit to start each repo with, but in practice that's of course unlikely to happen.
I believe there is a known commit hash that's there in the datamodel. So it would be possible to treat this as NIL with just changes an the UI level. I agree it's a deficiency, though I don't think it's the most important problem with git (the huge inconsistencies around the staging area are much more important IMO).
> Lastly, and not entirely unrelated: many, but no good solutions for sub-repositories.
I don't think a good solution is possible, personally. The repository is the unit of history, branching, tagging and so on, and that makes for a nice model that I don't want to change. If you have multiple repositories, it's better to deal with them as such.
The differences aren't huge, either. It would not take much effort to implement the final 20% of functionality to make git submodules useful. But it's just been left as a half-finished, half-broken feature that is not good for anything.
Whilst I can live with mercurial having lost the VC war (and prefer git on the whole) I am a bit annoyed that few of the good features that hg has over git seem to have been adopted by the latter, even where conceptually compatible (I believe git bundle is hg inspired, but it's pretty fringe to start with).
I disagree that git deals well with non linear history, everything about dealing with non-linear history in git is pretty painful, from bisecting to querying (compare to revsets in mercurial, for example) or logging.
Multiple independent repositories across a single org (working on one product) don't work well, in my experience. Unless your org is large enough to hit scalability problems monorepo seems the way to go with git -- it makes it easy for everyone to find stuff and use a consistent shared "timeline". However, other than submodules and co in git being a tire fire, I see no reason why the same purpose could not be served by subrepos in many cases; what makes you think they are inherently problematic?
That's a non-answer and sacrifices most of the benefits of using a DVCS at all; if you're going to do that you might as well just use SVN. What are the semantics you would want/expect reverting a merge to have? As far as I'm concerned, other than having to pointlessly pass "-m 1" every time, reverting a merge does exactly what I'd expect it to.
> I disagree that git deals well with non linear history, everything about dealing with non-linear history in git is pretty painful, from bisecting to querying (compare to revsets in mercurial, for example) or logging.
Bisect works fine. Could you be more specific?
> Unless your org is large enough to hit scalability problems monorepo seems the way to go with git -- it makes it easy for everyone to find stuff and use a consistent shared "timeline".
IMO the repo is the unit of versioning; things that are released together should go in the same repo, while things with separate lifecycles should have their own repositories. That way your tags and history work the way you'd expect, but you avoid showing a misleading global timeline if that doesn't actually exist (e.g. if a project depends on a previous release of an internal library, it's misleading to have that internal library in the same repository as that project, because you'd see the "current" version rather than the code you were actually using).
> However, other than submodules and co in git being a tire fire, I see no reason why the same purpose could not be served by subrepos in many cases; what makes you think they are inherently problematic?
I see them as inherently problematic because they hugely complicate the model. I don't want to think about different parts of the checkout being on different revisions, branches, or tags.
To avoid writing a treatise, I’ll just point to the advantages of distributed over centralized on Wikipedia, which is a list of stuff completely unrelated to merges.
I've got a feeling you are not being fully serious, so on that assumption instead of me explaining why this really not at all the case, how about you provide an example of a workflow that you think crucially depends on merging rather than rebasing, and we can discuss that?
> Bisect works fine. Could you be more specific?
Sure: given a test command, show me a simple git bisect invocation that finds the merge commit that broke master.
> things that are released together should go in the same repo, while things with separate lifecycles should have their own repositories.
I think this is a useful criterion, but one that tends to be only clear-cut for things like shrinkwrapped software (and it's not the only thing that matters). If you run a service of any complexity and with any sort of uptime requirements, you will not ship everything together, even if its part of a single feature and often you will have different versions of the same service in production in parallel as well. Al
> if a project depends on a previous release of an internal library, it's misleading to have that internal library in the same repository as that project, because you'd see the "current" version rather than the code you were actually using
A strange objection. Surely the point of having a super-repo would be that the subrepos at any one commit in the super repo would form a consistent state of the world, rather than you pinning inconsistent versions of different repos in the same commit of your super-repo?
> I don't want to think about different parts of the checkout being on different revisions, branches, or tags
At the most basic level you could think about the sup-repos like a pinned (yarn, poetry, budler, ...) dependencies and the super-repo as a lockfile with extra benefits (such as 'git diff HEAD^' presumably showing you all the source changes in the sub repos since the last time you committed their versions in the super-repo). If you are not directly working on code in any of the sub repos, you simply don't have to care about their different revisions, branches or tags. If you do want to make a change in one of the subrepos with a view to landing this change in the super-repo as well, it is true that you will probably create a new branch in first the subrepo, have that merged and then create a branch in the super-repo that switches it to the new version. But presumably the reason you don't just have a mono-repo to start with is because there is some degree of indepdendence (such as your proprietary app depending on an open source lib you also maintain). One realistic example from the open source world might be something like OpenBSD which is (if I remember right, apologies if I got something wrong) developed in one big (csv?) mono repo and that also includes all the bits that have made it into the wider unix eco system like OpenSSH or libreSSL. The cross platform versions of these are developed out of stream by people periodically pulling the whole OpenBSD repo as canonical upstream, copying the relevant subset of stuff across, updating their compatibility layers and pushing it to separate repos that contain just OpenSSH (or whatever). Presumably depending on goals and priorities, having OpenSSH be a sub-repo instead would offer benefits to at least some of the people involved (assuming a well designed sub-repo mechanism).
How about something along the lines of:
git stash --keep-index
git stash
git checkout right-branch
git stash pop --index
git stash pop
? Untested, so I might have messed up a detail.Another alternative is creating a tmp branch (again untested) and cherry-picking (with --no-commit) across.
git checkout -b tmp
git commit -m 'staged'
git commit -am 'unstaged'
git checkout right-branch
git cherry-pick -n tmp
git reset HEAD
git cherry-pick -n tmp^
git branch -D tmp GIT_AUTHOR_NAME='nil' GIT_AUTHOR_EMAIL='nil@example.com' \
GIT_COMMITTER_NAME='nil' GIT_COMMITTER_EMAIL='nil@example.com' \
GIT_AUTHOR_DATE='1970-01-01 00:00:01' GIT_COMMITTER_DATE='1970-01-01 00:00:01' \
git commit --no-gpg-sign --allow-empty -m 'NIL'
This will give you an identical commit hash every time. [Edit: added --no-gpg-sign as suggested in reply below]They still won't be consistent if you've enabled commit.gpgSign though. So, you'd want --no-gpg-sign on that initial commit or someone to reply with a better idea.
Until seeing your suggestion it hadn't occurred to me to use a fake user. However, using UNIX epoch was something I had been doing and I do have the 50 year sidebar ;)
I've also reverted merges many times in git with no issue. You just choose which parent you're reverting to and then it just works.
The only time I've seen branch merges in git really fuck up is one time when a novice git user at my company unstaged a file from the index before committing the merge. That was a disaster and took me hours to figure out what the hell was going on with that file.
I agree of course that SVN is much worse than git for most purposes, although it's still used frequently in preference to git in design artifact heavy settings because it won't choke as quickly as git on binary assets from artists or designers. The question of what tool handles merge commits better is a bit academic to me, so I do not know the answer. The two reasons for this are: 1. there is currently no practical benefit in learning a better VCS given the dominance of git 2. I gave up on using merge with git.
Make git-insert-empty-root a standard.
git rebase -i --root
[1]: https://git-scm.com/docs/git-rebase#Documentation/git-rebase...