7 ms·
> Git does not track historical branch names That's my biggest pet peeve on this list. Git branches are really just pointers to the HEAD of some commit history
by hn_throwaway_99 5y ago
> Git does not track historical branch names
That's my biggest pet peeve on this list. Git branches are really just pointers to the HEAD of some commit history, but if you've had a bunch of merges in the past it can be very difficult to tell which commit belonged to a particular branch at some point in the past.
Is there a good solution for this? Seems like it would be trivial to add a piece of metadata about which branch someone was on when a commit was made.
- db48x 5y agoGit _does_ keep track of historical branch names. It is called the reflog. For each ref there is a log of what commits it pointed to. See `git help reflog`.
- aaaaaaaaaaab 5y agoIf you keep your history linear by using rebase only, then this becomes a non-issue.
- anonymoushn 5y agoThis actually makes it much harder to answer the question "What happened with the branch of X name 2 years ago?"
- clintonb 5y agoWhat is the value of that information? When I’ve looked at older commits, I either want to know about the resulting code or the context (e.g., motivations, discussions). A fixup commit, or some other intermediate commit isn’t useful.
- elsjaako 5y agoIf you always rebase, aren't you hiding even more of the history than if you have unlabeled branches? I have to admit I've never understood the point of keeping the history linear.
- jolux 5y agoI find it easier to read linear history.
- brigandish 5y agoCould that be because if the history isn’t linear then it’s difficult to read, precisely because of the reasons given above, which would mean you have the same problem but you’ve simply decided to avoid it via a (legitimate) workaround and not complain. That wouldn’t make the complaint invalid though.
- jolux 5y agoI have to admit I don't fully understand the problem as originally formulated. I've never had trouble figuring out what's going on in a Git repository. I do agree that GitHub's interface for these things is anemic. As for that part, I typically squash-merge on GitHub and that links to the PR, which is good enough for me.
- kazinator 5y agoAnd that goes for this Fossil too. When I look at the SQLite timeline, I see confusing swimlanes. I can't make heads or tails out of some of it.
- kazinator 5y agoYou're also hiding history if you repeatedly edit the code while you're debugging it, and sometimes undo 17 changes and re-do them differently in your edit buffer and such. A True Scotsmans non-history-destroying version control system would reveal and be able to replay every single editing keystroke that went into a change.
- ISO-morphism 5y agoThere are two solutions that come to my mind, both are more by convention: 1. Always use merge commits (--no-ff) a la git flow, and leave the branch name in the merge commit. That doesn't get you the branch name on the commit, but it should help identify the branches. 2. Use a pre-commit hook to put the branch name or bug tracker ID at the bottom of the commit message. There are some tools built around this, I've done it at $DAYJOB with a custom python script I manually copy around into `.git/hooks/pre-commit`.
- rezonant 5y agoGood solutions. FF/rebase are very nice, but I've seen devs sleuth into a squashed PR commit, find the PR the features came from and read it on GH, and that's powerful. I saw a new dev do this recently. They dug into the original summary of the changes from the dev (for a PR that landed 6 months before they joined) and the flow of conversation around the work. They had insights into the decisions the team made around the feature as it was developed. The PR linked to the product artifacts that led to the work, so they had the business context. They nailed the implementation, first time :-) There's a nice benefit to doing merge/squash and providing a link to a set of context around the specific set of commits, not just a contextless line of commits, as clean as it may be.
- kazinator 5y agoGit merge does something pretty awful; it takes multiple changes and turns them into a single patch bomb in the destination branch. What if the branch has 17 commits, the 9th of which introduces a regression? Moreover, suppose that the 9th commit of the original branch didn't exhibit the regression; rather, its change had that effect when it was merged into master. You need all 17 commits, in their rebased versions, on master, so you can search through their history (e.g. with git bisect) and discover that the 9th one broke it. Rebase is the correct thing: it calculates a new sequence of commits that are individually merged, and retained as separate commits that you can dig through in the new branch. What's missing is this: the rebase of an entire branch into a new branch should record a second commit parent (for the final commit of the operation), pointing to the final commit of the original branch. Like this: X-Y-Z--<< branch / -A-B-C-D-E--<< master rebase it: X-Y-Z--<< branch / \___ / \ -A-B-C-D-E-X'-Y'-Z'---<< master where X', Y', Z' are the rebased versions of X, Y, Z. A regular git rebase is missing that second parent link from Z' to Z. You just get this: X-Y-Z--<< branch / / -A-B-C-D-E-X'-Y'-Z'---<< master The only way you can identify that Z' was cherry-picked from Z is by clues in the commit message: identical commit message text, or something like a Gerrit Change-Id. Possibly, each cherry-picked commit should have the original as its parent: X-Y-Z--<< branch / \_\_\___ / \ \ \ -A-B-C-D-E-X'-Y'-Z'---<< master now that is almost like iterating over the branch and doing a commit-by-commit merge. At first we pretend that the branch is just X, and merge it to get X'. Then we merge Y', and then Z'. We never merge a sequence of two or more commits into one. If you do that, you have both: nobody can say you're not merging, but you have the effect of a rebase. A rebase (cherry-pick) is a kid of merge: of one commit (at a time), without recording all the parents. A case can be made for rebasing commit-at-at-time using merge. (Not for private work, obviously; just already published, permanent history). The nice thing about rebase is that it doesn't introduce the crufty parentage, which makes it ideal for rearranging unpublished history and then presenting a clutter-free end result.
- kazinator 5y agoThe Gerrit review system tags every change (i.e. commit) with a durable Change-ID, which is represented int the log message, usually as the last line, like this: Change-Id: I7321a7fddab667af7a418eeeb7d48c0240570260 The Change-Id will be the same whenever that commit is cherry-picked anywhere, even if it has to change due to merging. It is not a hash, but a random UUID. If you trowel through the log messages you can find the places where that change has "been" by looking for the Id.
- wildfire 5y agoA common problem when using Gerrit is the Change-Id being copied across from different branches (via, for example, git cherry-pick). The idea is ... interesting, but the implementation of Change-Id has quite a few problematic corner-cases which make normal git operations (rebase, cherry-pick, merge) more delicate than the need to be.
- Buttons840 5y ago> Seems like it would be trivial to add a piece of metadata about which branch someone was on when a commit was made. I often make commits without being on a branch at all (detached head). I like this about Git.