简体   繁体   English

Git(Bitbucket)创建备份版本

[英]Git (bitbucket) creating backup version

I am wondering what the standard procedure is to create an easy to find stable backup version of a git project. 我想知道创建易于找到的git项目的稳定备份版本的标准过程是什么。 Ideally, it should not be necessary to go through the git logs, find a certain version and revert. 理想情况下,无需遍历git日志,查找特定版本并还原。 Ideally, a version would be tagged. 理想情况下,将对版本进行标记。 I saw git (I am using bitbucket) allows to create branches and some of those branches seem to have a tag release which In like because it indicates it is a stable version. 我看到git(我正在使用bitbucket)允许创建分支,并且其中一些分支似乎具有标记发行版,就像这样,因为它表明它是一个稳定的版本。 Is branching out and switching back to the main branch for further a good way to manage this or are there better solutions available. 正在分支并切换回主分支,以寻求进一步的好方法来管理此问题,或者是否有更好的解决方案可用。 I am not very familiar with git and its mechanics, so I would be happy to get some pointers towards good conventions. 我对git及其机制并不十分熟悉,因此我很乐意获得一些指向良好约定的指示。

Use Tags 使用标签

You can use git-tag to create tags, with or without annotations. 您可以使用git-tag创建带有或不带有注释的标签。 git tag --list will show you the available tags, and git-show can be used to view the annotation of a given tag. git tag --list将显示可用的标签,而git-show可用于查看给定标签的注释。 You then have to push the tags upstream, using git push --tags or similar. 然后,您必须使用git push --tags或类似方法将标签推入上游。 For most other purposes, you can treat a tag as a commitish for selecting commits. 对于大多数其他目的,您可以将标签视为选择提交的提交。 For example: 例如:

git tag --annotate --message="Release message 1" release01
git push --tags origin
# code ...
# code ...
git tag --annotate --message="Release message 2" release02
git push --tags origin
# code ...
# code ...
git tag --list
git show release02
# code ...
git reset --hard release01

Pragmatically, you can use the name of a tag almost anywhere you could use a commit ID. 实用上,几乎可以在任何使用提交ID的地方都可以使用标记的名称。 You can use it to reset your branch, as a branch point to create new branches, and so forth. 您可以使用它来重置分支,将其作为创建新分支的分支点,依此类推。

Download Archives from Tags 从标签下载档案

In online services like Bitbucket, GitHub, or GitLab, every tag you create triggers an archive build, which you can download as a zipfile or tarball from the tags/releases widgets. 在Bitbucket,GitHub或GitLab等在线服务中,您创建的每个标签都将触发一个存档版本,您可以从zip / release小部件中将其作为zipfile或tarball下载。 In Bitbucket, you can navigate to your available downloads at: 在Bitbucket中,您可以通过以下网址导航到可用下载:

https://bitbucket.org/<username>/<repository>/downloads/?tab=tags

In Bitbucket, you will see a screen with archives in zip, gzip, and bzip2 format for each tag in the project. 在Bitbucket中,您将看到一个屏幕,其中包含项目中每个标签的zip,gzip和bzip2格式的存档。 Just click the format you want to download it. 只需单击您要下载的格式。

图:Bitbucket标签档案

This archive feature is common to most of the popular online Git hosts, but features and navigation to the archives may vary. 大多数常用的在线Git主机都具有此存档功能,但是存档的功能和导航可能会有所不同。 To create the archives locally, just use git-archive from the command line instead. 要在本地创建档案,只需在命令行中使用git-archive即可

I'm sure there will be others with more complete answers, but here are some tips: 我敢肯定会有其他人获得更完整的答案,但是这里有一些提示:

  • Git != Bitbucket. Git!= Bitbucket。 Git is the version control system, Bitbucket is a git project hosting platform. Git是版本控制系统,Bitbucket是git项目托管平台。 You could just as easily work with a git repository hosted on bitbucket, github, a vps, or your local computer. 您可以轻松地使用托管在bitbucket,github,vps或本地计算机上的git存储库。 Bitbucket adds a nice user interface for viewing 'releases' and such, but underneath it is all just git. Bitbucket添加了一个不错的用户界面来查看“发布”等内容,但在其下方仅是git。
  • Yes, tagging and branching are major things used: 是的,标记和分支是主要使用的东西:
    • tagging: any commit in git can be tagged. 标记:git中的任何提交都可以被标记。 These tags can then be used as references. 然后可以将这些标签用作参考。 You could make tags like v1.1 , v1-stable , v1-beta to indicate stable or testing versions, etc. Usually used for marking particular revisions for various purposes (often releases). 您可以制作诸如v1.1v1-stablev1-beta类的标签来指示稳定或测试版本等。通常用于标记出于各种目的的特定修订版(通常是发行版)。
    • branches: these are parallel sequences of commits - many projects use something like a stable master branch where commits are only merged to it when thoroughly tested, and a dev branch where main development happens on. 分支:这是提交的并行顺序-许多项目使用的是稳定的master分支(仅在经过全面测试后才将提交合并到它)和dev分支(主要开发在此进行)之类的东西。 Used for tracking development, especially when adding new features that require multiple commits, or trying out something different that you don't want in master . 用于跟踪开发,尤其是在添加需要多次提交的新功能或尝试在master不需要的其他功能时。
  • You can 'checkout' any commit, tag, branch, etc. on your computer, which sets all the tracked files to their state as they were at that point. 您可以“签出”计算机上的任何提交,标记,分支等,这会将所有跟踪的文件设置为它们当时的状态。 This means that whatever system of branching/tagging you use, you can always revert back to any commit/tag/branch you want. 这意味着无论您使用哪种分支/标记系统,都可以随时恢复到所需的任何提交/标记/分支。
  • Have a look at how other projects manage this. 看看其他项目是如何管理的。 For example, the rust project on GitHub . 例如, GitHub上rust项目 They have multiple branches (eg. stable , master , beta ), and releases are tagged (eg. 1.0.0-beta , 1.5.0 ). 它们具有多个分支(例如stablemasterbeta ),并标记了发行版本(例如1.0.0-beta1.5.0 )。
  • Version control is a huge topic, and no single 'best' way to manage development. 版本控制是一个巨大的主题,没有一种管理开发的“最佳”方法。 I'd suggest reading up on it (vcs in general, and the functions git gives), looking around at other projects, and most of all, jumping in and trying things yourself. 我建议阅读它(通常是vcs,以及git提供的功能),环顾其他项目,最重要的是,亲自尝试一下。 Sooner or later you'll settle on a workflow that suits you or your projects' development style, whether it be tagging, branching, other features, or a combination of all. 迟早您会选择适合您或您项目开发风格的工作流,无论是标记,分支,其他功能还是所有功能的组合。

You can add a tag and push it to the remote: 您可以添加标签并将其推送到遥控器:

git tag <tagname>
git push origin --tags

This would tag the current commit and push that new tag to the remote you cloned from. 这将标记当前提交并将该新标记推送到您从中克隆的远程服务器。 Checking out a particular branch or commit would let you tag that using this same mechanism. 检出特定的分支或提交将使您可以使用相同的机制对其进行标记。 As stated in other answers, deciding on your tagging strategy is a different matter altogether, but this is the mechanism you use to create the tag and distribute it. 如其他答案所述,决定标记策略完全是另一回事,但这是您用来创建标记和分发标记的机制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM