Question

In the list of tags like

v001
v002
v003
v004
v005

I pulled new tag lets say v006 by git fetch --tags and git checkout v006.

By mistake I failed to note which version was checked out (git describe --tags) before this new checkout. There seems to be error and I have to revert back to old tag. How do I know which tag was used?

Était-ce utile?

La solution

The HEAD reflog records each successful checkout along with the text "moving from (point A) to (point B)", e.g.:

$ git reflog
676699a HEAD@{0}: checkout: moving from
        695326c489285ed5678ac04d58289bcb24019bb9 to tag2
695326c HEAD@{1}: checkout: moving from master to tag1

In this case I started on master and then did git checkout tag followed by git checkout tag2. (Note: I edited the output slightly to make this more suitable for posting. If you have git set up to pipe through "less" you may have to scroll left/right in your window to see everything.)

The first output line (which I wrapped so that it's the third quoted line) has a raw SHA-1 because when you check out a reference that is not a branch (or, when you use --detach with a branch) you get a "detached HEAD", where the HEAD file records a raw commit SHA-1. However, we can see from the next line that 695326c489285ed5678ac04d58289bcb24019bb9 is the SHA-1 for tag tag1.


Note: you say "There seems to be error and I have to revert back to old tag", and refer (via Stack Overflow tags) to git-revert. However, these kinds of git checkout (by tag or SHA-1) are about looking at some other version (i.e., getting a specific version into your work directory). The git revert command is about adding a new commit whose effect is to undo some old commit.

In general you only want to git revert if you are "on a branch" (as in, git checkout master or git checkout develop or some other branch name), and you discover that someone committed incorrect code to that branch, and need to "reverse apply" their previous change and make that a new commit (which you would then probably publish, either git push or make a pull request). So it seems odd to rever to "reverting" when what you have been doing is looking at old versions.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top