converting git branch to git tag

笑着哭i 提交于 2019-12-01 04:09:47

Short answer: it's not a problem. And creating tags the way you propose is okay, although I suggest you use the -m option to create an annotated tag with a comment (see man git-tag), as this will create a "first class" tag that will be used by git describe etc. without additional arguments.

Long answer: Remote branches will not affect the local branches directly. If I create a branch from a branch or a tag from your public repo, when you delete that branch, and I fetch your repo, I will see that your branch is gone, but my branch is still complete in my repo.

Brances are only symbolic names for the a commit in a git repo, when you commit the HEAD and the branch you're working on points to the new commit. A tag is also a symbolic name for a commit, but this is not changeable (you can delete it, though, but it cannot be changed), so it points to a fixed location in the history, while a branch point to the moving head of one line in the history. Since commits in git have zero, one or more parent commits (zero for initial commit, one for a normal commit, more than one for a merge), even if the original branch or tag is deleted from the remote your local repo still have a pointer to you local branch and from this you can find a common ancestor (assuming the branches are related in the first place), so you can still merge in changes done to any of your branches into master.

Coming from svn to git can be a bit confusing at first. It sounds like you're still thinking in svn terms, making everything more confusing. I think it's easier if you think of git more as an advanced filesystem (which is what Linus Torvalds were when he wrote it), instead of a source control tool. I also suggest you take some time to read (or skim through) git for computer scientists, it's not as daunting as it sounds; and having a better understanding of how it actually works will help you thinking the "correct way". ;)

As I understand it, you want to create tags instead of branches and thereby prevent others to continue committing on these branches.

Unfortunately, you cannot prevent people from creating branches from wherever they want, especially since Git is a decentralized VCS. However, you can decide whether a commit can be pushed to a central repository. So you could write hooks that would forbid commits that have specific commits in their ancestors.

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