“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
"git checkout tag-name" vs "git reset --hard tag-name"
提问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
HEAD
pointer, keepsBRANCH
pointer)
- 将您从分支中分离出来。(即移动
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
HEAD
andBRANCH
pointers)
- 不会将您与分支分离,而是使之前的提交变得“悬空”。(即同时移动
HEAD
和BRANCH
指针)
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 reset
or checkout
, considering that a pull
is always done prior to this update call?
考虑到 a总是在此更新调用之前完成,是否应该使用reset
或对标签进行生产更新?checkout
pull
采纳答案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-name
will 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 上)进行更新。