“git checkout tag-name” vs “git reset --hard tag-name”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10751237/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 13:46:25  来源:igfitidea点击:

"git checkout tag-name" vs "git reset --hard tag-name"

git

提问by Tower

I know that there are questions like this, but that's not what I'm asking.

我知道有这样的问题这样,但是这不是我在问什么。

I also know that:

我也知道:

git checkout tag-name:

git checkout tag-name

  • Detaches you from the branch. (i.e. moves HEADpointer, keeps BRANCHpointer)
  • 将您从分支中分离出来。(即移动HEAD指针,保持BRANCH指针)

git reset --hard tag-name:

git reset --hard tag-name

  • Does not detach you from the branch, but makes the previous commits to become "dangling". (i.e. moves both HEADand BRANCHpointers)
  • 不会将您与分支分离,而是使之前的提交变得“悬空”。(即同时移动HEADBRANCH指针)

I wonder which one makes more sense for updating to a tag, i.e. should a production be reseted or checked out. I know that a garbage collector may run, removing dangling commits, but then again, if the production is always "pulled" before the process of updating to a tag, I see nothing bad there.

我想知道哪一个更适合更新标签,即是否应该重置或检查产品。我知道垃圾收集器可能会运行,删除悬空的提交,但话又说回来,如果在更新到标签的过程之前总是“拉”生产,我认为那里没有什么不好的。

Should a production update to a tag with resetor checkout, considering that a pullis always done prior to this update call?

考虑到 a总是在此更新调用之前完成,是否应该使用reset或对标签进行生产更新?checkoutpull

采纳答案by AD7six

I wonder which one makes more sense for updating to a tag

我想知道哪一个更适合更新标签

Your production install should be checking out a tag.

您的生产安装应该检查标签。

Think of it this way: your production install is read-only. git reset --hard tag-namewill modify the currently checked out branch.

这样想:您的生产安装是只读的。git reset --hard tag-name将修改当前签出的分支。

Alternatively

或者

It's common practice that in addition to creating a tag, you have one branch which is simply the latest release. In which case you'd e.g. merge to master and create a tag from there; and on your production installs you'd update simply with git pull (on master).

通常的做法是,除了创建标签之外,您还有一个分支,它只是最新版本。在这种情况下,您可以合并到 master 并从那里创建一个标签;在您的生产安装中,您只需使用 git pull (在 master 上)进行更新。