How does Git handle branches compared to SVN?

柔情痞子 提交于 2020-01-05 12:08:58

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!