可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
Since Git has the ability to keep track (and keep it clean) of branches with completely different content from each other, in the same repository, some projects (like Git itself) have started to make use of it.
Git, for instance, uses one branch for the code itself, while keeping its documentation in a separate branch. Same repo, just different branches.
It might just be me, coming from a SVN background, but I find it confusing to have 'nothing in common' in those branches. Development/staging/production branches; those I understand. Branches for incomplete features; sure, I'm doing those too. Heck, have your documentation with one branch per language. But no files in common?
Is this just (perhaps an underused and/or undermarketed) feature in Git, that everyone should embrace and get used to, or a possibly dangerous misuse by someone being lazy of not differentiating two aspects of the same project enough?
回答1:
I personally would not store different content in different branches; in the case of docs and code, I would just make a myproject.git and a myproject-docs.git (and sub-module the docs into the code if it was necessary for the build process).
On the other hand, nothing bad will happen if you do this. Git is not going to tell you what to do, so you are free to make your own decision on how you want to use it. So to answer your question, it's neither a killer feature, nor something that will bowl you over if you are not careful. It's just how someone choses to use it.
回答2:
Git tracks coordinated changes in (text) files within a project, so it doesn't know or care whether branches are mergable or not. Having independent branches in a Git repo is similar to having independent projects in a Subversion repo, which is a common practice (because of svn's overhead).
Because Git's data structure is very different than SVN's, you can do different things with them. In SVN a feature branch is somewhat unusual, and a feature branch which is not often merged to the trunk might be a "bad smell", a sign that the programmer has "gone dark" and is creating code that may never be able to be integrated into the project. In Git, a feature branch is a perfectly safe and sensible workflow.
So they can be used in different ways because Git is not SVN even though both have repositories and branches and commits, and serve the same general function of source control.
As I got more experience of Git, what had been weird just became different. Then I got curious about what I could do with that different tool.
回答3:
I'd say it's more like a lazy workaround for the fact that Git can't currently handle having multiple projects stored in the same repository. You can do it, but there's no way to pull down just the one you want.
I say "lazy", because it wouldn't have been too horribly tough to add the feature when the git developers themselves discovered a need for it (for storing docs). Since they used this weird branch hack, their incentive to fix the issue for everyone else has abated significanly.
回答4:
The benefit to doing this, is that it's possible to pull only the docs branch if that's all you're interested in. Like jrockway said, you can do this using another repository and submoduling if necessary, but with this ability to create a 'naked' branch, you have the option not to.
Personally, I'm still on the fence about this. I understand why it could be beneficial, but I'm not wholly convinced it's the best way to go.
回答5:
I think it depends on what your project is.
Git is obviously a community OSS project so having the docs in the (same) repository so everyone gets them makes sense (to me).
On the other hand I would not store the docs for my projects at work as I would rarley edit them except on 'let's update the docs' type of ticket. At work I don't want my docs intermingled with my source, I just want the source (typical programmer view i know).
Others may want them all-together. I think you just need to realize what it means (remember everyone has a full copy of the repository) and pick the best option for your project.
回答6:
It's a little weird when you're used to the Subversion model of presenting the tree to users, but once you get used to the model it's a lot less confusing.
A git repository is just a tree of objects that explain how to transform a directory from one state to another. Those objects have a parent. Some objects have two (or more) parents; merges. Some objects have no parent; the initial commit.
As I understand it, internally, Subversion's model is similar minus the concept of where merges came from. Those are just new commits with a handy command (svn merge
) for getting a patch of the differences between two other commits.
I actually use this feature rather often to manage config files that started from the same directory on separate hosts, like /etc/apache2
. It's like saying, "this is the alternate start of this stuff, but it's been abandoned". It allows me to stash the state of some files before I overwrite them, but without having to worry about whether they merge right, or are even related to the master branch at all.
In Subversion I'd have to stow that backup in some un-related place (zip file somewhere) or in a subdirectory in the repository. Plus, in subversion, if I delete any reference to those files in the current view of the tree it becomes very hard to find them again.