“git checkout tag-name” vs“git reset --hard tag-name” [英] "git checkout tag-name" vs "git reset --hard tag-name"
问题描述
我知道有类似于,但这不是我要求的。
我也知道:
git checkout tag-name
:
- 。 (即移动
HEAD
指针,保持BRANCH
指针)
git reset --hard tag-name
:
- 不会将您从分支中移除,但会使先前的提交变为悬挂。 (即移动
HEAD
和BRANCH
指针)
我想知道哪一个更适合更新到标签,即生产是否应该重新设置或检出。我知道一个垃圾收集器可能会运行,删除悬而未决的提交,但是,如果在更新到标记之前总是拉生产,我会发现没有什么不好的。
如果生产更新到
reset
或checkout
的标签,考虑到pull
总是在此更新调用之前完成?解决方案
我想知道哪一个更适合更新标签
您的产品安装应该检出标签。
以这种方式考虑:您的生产安装是只读的。
git reset --hard tag-name
会修改当前签出的分支。
strong>
通常的做法是,除了创建标签之外,您还有一个分支,它只是最新版本。在这种情况下,你可以合并为主并从那里创建标签;并且在你的产品安装中,你只需使用git pull(在master上)来更新。
I know that there are questions like this, but that's not what I'm asking.
I also know that:
git checkout tag-name
:- Detaches you from the branch. (i.e. moves
HEAD
pointer, keepsBRANCH
pointer)
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)
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
orcheckout
, considering that apull
is always done prior to this update call?解决方案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.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).
这篇关于“git checkout tag-name” vs“git reset --hard tag-name”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
- 不会将您从分支中移除,但会使先前的提交变为悬挂。 (即移动