问题
Relatively simple question but I can't find much on the internet. All my search results simply show how to use git branches but doesn't explain how its different.
I know that with SVN, creating a new branch of the trunk means to create a full copy of the trunk, into the 'branches' directory, and I also know that Git does not create full copy like SVN - so what does it do? This is more for writing facts in my DVCS research documentation rather than anything.
Perhaps an extension to this would be how git handles tags as compared to SVN?
Thanks in advance.
回答1:
In git, a branch is a just a pointer to a certain revision. At any point, you can go back to any old revision (git checkout [revision]
), point another branch at it (git checkout -b new-branch
), and start working from that point onwards.
You can use the gitk
command to browse the tree of branches, and you can create branches by right clicking on revisions etc. This tool often helps make what is going on under the hood clearer. (If you are on Mac OS, there is also gitx, which I can't live without)
回答2:
To put it simple: in Git, a branch is just like a tag, with the difference that this tag is moved by Git itself.
In other word: a branch just point a commit. And when you're on a branch and you commit, a new commit is created, and the "branch tag" is updated.
To make is less theoretical you can go in .git/refs/branches
and you'll see a file per branch. Those files just contain the sha1 of the commit they're pointing at.
来源:https://stackoverflow.com/questions/21766283/how-does-git-handle-branches-compared-to-svn