As a member of some project, you can add tags to your repository. Tags are nice for adding annotations to your history. Tags don’t change your commit history but they can be used as a sort of bookmark. I often use tags for highlighting new versions or milestones in my projects. When you submit
lab3, that is a sort of milestone that says “OK, I’ve finished the data structures. I’m ready to move on to the crawler! (
lab4).” A couple of weeks (or months or years) from now you might be interested in revisiting the state of your code when you had finished the hashtable, for example. Rather than trying to remember some long git hash for your last commit of
lab3, and to help us (and your future selves), we want you to add a
tag to the project to indicate when the work is complete for
lab3. By default
git tag TAGNAME will add a tag to the current
HEAD of your working tree.
$ git tag lab3submit
You can also add a
tag to a previous commit—–this might be useful if you charged ahead and made a few commits but want to go back and mark some commit in the past with a
$ git tag oops d4fd63a
If you accidentally add a
tag or add a
tag to the wrong commit, you can always delete a
tag by using the -d flag and identifying the
tag by the name you gave it.
$ git tag -d oops
Adding tags, currently, has only annotated our commit history locally. Don’t forget to push your tags (you must do so explicitly as follows) to the remote so that your locally created tags are visible to other people that have access to your repository that lives on GitLab.
$ git push --tags
Once you’ve pushed your tags to the remote, you should go to GitLab and verify that you can see any tags that you’ve created and pushed. On the main page of your project (in GitLab) you should see buttons for
tag(s) (NOTE: The GitLab web interface is smart and will update the text of these buttons in accordance with the number of “things”. For example, if you have 1 commit it will say
1 commit, not
1 commits. This is why I included the parentheticals for the commit/branch/tag button text. A small but nice feature :). Click on
tag(s). Alternatively, you can click on the “commits” icon in the left navbar and it will take you to a screen where you can browse things like commits, branches, and tags.
To learn more about
git tag, run
git help tag.
For the sake of transparancy, let’s take a quick look at how we, as graders, will use the tags you create to checkout appropriate versions of your code. For example, we will do something akin to the following when we go to grade your lab3 submission:
Clone the student repo.
$ git clone URL
List any/all existing tags—we should hopefully see the appropriate submission tag (e.g., lab3)
$ git tag -l
Now we can checkout the code that was in the repo at the time of that tag (i.e., the state of the code at the time of submitting lab3).
$ git checkout tags/lab3submit
If you prefer, you can create a new branch from the code base at the point of the specified tag; you can now freely edit the code and there are no concerns about messing up anything on the master branch.
$ git checkout tags/lab3submit -b lab3testing