I know that there are questions like this, but that's not what I'm asking.
I also know that:
git checkout tag-name
:
HEAD
pointer, keeps BRANCH
pointer)git reset --hard tag-name
:
HEAD
and BRANCH
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
or checkout
, considering that a pull
is always done prior to this update call?
git reset is specifically about updating the index, moving the HEAD. git checkout is about updating the working tree (to the index or the specified tree). It will update the HEAD only if you checkout a branch (if not, you end up with a detached HEAD).
Git Checkout Tag The command makes the repository go into Detached HEAD state. The state allows viewing, making changes, and committing. However, no specific branch is tracking these changes. To confirm this, run the following command: git branch.
To review, git reset is a powerful command that is used to undo local changes to the state of a Git repo. Git reset operates on "The Three Trees of Git". These trees are the Commit History ( HEAD ), the Staging Index, and the Working Directory. There are three command line options that correspond to the three trees.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With