Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

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, keeps BRANCH 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 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?

like image 651
Tower Avatar asked May 25 '12 08:05

Tower


People also ask

What is the difference between git reset and git checkout?

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).

What is git checkout tag?

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.

What is reset hard in git?

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.


1 Answers

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).

like image 111
AD7six Avatar answered Sep 28 '22 10:09

AD7six