A branch's HEAD is a pointer to a commit. A branch itself is a logical collection of commits grouped together. If you add a commit on top of a tag, you have a floating commit. If you add it to the head of a branch, you're still on that branch, and the new commit is part of the collection of commits referred to by branchname. It's an organizational construct in addition to a conceptual one.
No, a branch is a pointer to a commit too. That's what it is in git. That commit can have a parent, just like a tag's commit can have a parent, thus creating your "logical collection of commits". But the branch/tag itself is just a single commit.
The difference, as you mentioned, is what happens when you create a new commit while having the branch/tag checked out. Which is why the tag solution is better.
Both are pointers to commits, but tags never change.
Once I release v1.4.5, that should NEVER change. I tag that commit and move on. If I need to make changes off of that I create a new branch starting at v1.4.5, do my development on this new branch, and when I'm done I tag the final commit as v1.4.6 and merge and delete the branch.
Both are pointers to commits, the only difference is that the commit a tag points to does not change. This means that I don't have to deal with someone making a commit on the v1.4.5 branch by accident and all of a sudden a client's 1.4.5 is different from the 1.4.5 in my repository.
I agree with your distincting that a tag is immutable and the head of a branch is mutable. However, the branch itself is the head and a bunch of extra stuff that only makes sense because there's a mutable head. A branch can track upstream branches on remotes. If you're on master, and you pull upstream's master, you might get 5 commits that are all "part of master" for lack of a better way to phrase that. If you fetch the tag, sure you'll get the parent commits, but I would argue that there's a conceptual difference there. Also, if you run git pull, you'll get changes to branches but you won't get tags unless you add --tags. Same for pushing. This makes logical sense, because branches change all the time and tags don't; branches are primarily used for collaboration and tags aren't. Branches, in addition to having a mutable head, have a bunch of metadata that makes them different from tags, and git treats them differently, so there's a practical difference as well as conceptual. I'm not arguing that a branch "points" to more than one commit so much as I'm arguing that git treats them differently, that there are implications to that difference in mutability that are the core difference between a branch and a tag.
Which is why the tag solution is better.
To address the other half of your comment, I'm obviously not suggesting that one abandon the concept of tags altogether. They can be useful precisely because of their immutability as you clearly spell out. But just because they fulfill a role doesn't mean there's no value in not also having a branch there. I am suggesting that if you're going to essentially implement a branch using tags, you don't really gain much from not actually having a branch with them, and you lose all of that collaborative metadata and interface niceties I was talking about. To be clear, I'm also not suggesting a v1.4.5 branch. Depending on circumstance perhaps a v1 branch, or a v1.4 branch, and commits on it could be tagged v1.4.5 etc. It makes sense for the latest version of v1.4 to be mutable because you're eventually going to make a v1.4.6, a new version of the v1.4 line. OP has made a clear argument for why he would choose to not include a v1.4 branch, but I believe having one has more pros than cons. Again, that's just my opinion based on the experiences I've had using GitFlow and variations for the last seven years or so.
But yes, I do understand the difference between branches, branch heads, and tags, thanks :) have an upvote.
You can create a v1.4.x branch to track the latest tag. So instead of picking the latest among v1.4.0 v1.4.1 v1.4.2 v1.4.3 v1.4.4 v1.4.5 you get it completely automatized and foolproof.
People accidentally commit to the wrong branches way too often for me to call any system "foolproof"...calling a system "foolproof" is just asking for the world to invent a better fool =)
I think you're forgetting the context in which we discussed this. You can't move a branch that's tracking a version you released to the client. In the same way you can't go back in time and hand the client a different version of your software.
Sorry, I thought we'd switched contexts from your article to git in general when you started trying to teach me how git works.
Let me try explaining my point of view a different way. Lets follow your tagging example.
I have a client. I make a build of my software for them. I tag the release c1-v1 for client 1 version 1. I continue my development in a branch somewhere.
The client comes back and needs a bug fixed. I stop what I'm doing, git checkout c1-v1, make whatever changes I need to make, create a new commit on top of the tagged commit, git tag -a c1-v2, and release that to the client. Another bug comes up, c1-v3, and then c1-v4.
I believe this is following your model correctly. My development is taking place in a branch somewhere, and every release I've given to a client is tagged with no branch associated with it. If I repeat the process for 10 hot fixes over 10 different clients, that's 100 tags. They're all nicely named, so I can run git tag -l and look through the list to see what the largest version for c1 is and so on.
This has the advantage that the client can say "I'm running c1-v16" and you can instantly type that into a git checkout command and be where the client is. That's great.
But if you look back at what you're naming your tags, you'll see that all of the client tags start with c1, and they're all in a row, and you're always adding new commits onto whatever the latest c1 tag was. It's almost like c1 is a branch name. You're manually advancing HEAD on your branchless branch each time you create a new commit and tag it, while a real branch does this automatically. You can push and pull branches, but doing that with your branchless branch is more difficult. Tools that deal with revision history, like those fancy graphs you have screenshots of, will have a tag and a commit message for every single commit, and some of them won't draw any pretty lines for it that, as I mentioned elsewhere, are actually fairly convenient for tracking logically grouped changes in a codebase.
I believe I understand what you're proposing, and it has advantages, and maybe it's a good fit for some development situations. I personally don't think it fits my needs very well.
I think I know what you're getting at. This is the case when you need to maintain completely separate versions of your project (in your case, for different clients). Somebody mentioned that in the comments of the article already.
I would agree that branches are better in that case, but that's not really GitFlow anymore, so the article doesn't really deal with that topic. In my mind, this is a difficult thing to do properly no matter what method you use.
And the tag benefit over a branch is obvious - you can rollback to a tag. In your example, with a branch, you lose the history of your client's versions. In the case you described, it's pretty obvious that you don't need that history, and that's why a branch is better for you.
I disagree, that's exactly GitFlow. GitFlow is designed to make it easy to support multiple different released versions of the software simultaneously. They're not completely separate, they're different versions of the same product. In my example I had used the word client to make it easier to distinguish using "c", but don't let that cloud the issue. I'm talking about multiple, related, simultaneously supported versions of a single product.
you can rollback to a tag
You can get your working directory to the state of any commit you want by specifying the hash. Git log is going to list them in the order they were produced, and I can always checkout HEAD again to get back to the latest incarnation of a particular version. Nothing is "lost" except the ability to specify a commit by a friendly name instead of a complicated hex value. You seem to have a good grasp of git, so I have to assume you understand this basic principle, and as such I have no idea what you're trying to convey with that paragraph.
Anyway, it's been interesting debating it with you, thanks for the mental exercise :)
You can get your working directory to the state of any commit you want by specifying the hash. Git log is going to list them in the order they were produced, and I can always checkout HEAD again to get back to the latest incarnation of a particular version. Nothing is "lost" except the ability to specify a commit by a friendly name instead of a complicated hex value. You seem to have a good grasp of git, so I have to assume you understand this basic principle, and as such I have no idea what you're trying to convey with that paragraph.
Yes, I realize that. The problem is that without tags, you have no idea which of the (potentially very many) commits on branch c1 built the software that your client C1 was using at past points in time. Like I said, this is not something that you care about when you gave the example (you only care about the newest version), and that's the reason that those tags don't make sense to you.
I guess you could version your software with the commit hash, but I'm not sure your clients would be too thrilled about that :).
Anyway, it's been interesting debating it with you, thanks for the mental exercise :)
11
u/[deleted] Jun 19 '15
A branch's HEAD is a pointer to a commit. A branch itself is a logical collection of commits grouped together. If you add a commit on top of a tag, you have a floating commit. If you add it to the head of a branch, you're still on that branch, and the new commit is part of the collection of commits referred to by
branchname. It's an organizational construct in addition to a conceptual one.