Extra - Using Git Tags
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 changed ahead and made a few commits but want to go back and mark some commit in the past with a tag
:
$ 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
Similarly, if you’d like to delete a tag, make sure also to delete it on the remote repository:
$ git push --delete origin oops
Once you’ve pushed your tags to the remote, you should go to GitHub and verify that you can see any tags that you’ve created and pushed. On the main page of your project (in GitHub) you should see buttons for commit(s)
, branch(s)
, releases
, and contributors
. Click on releases
, and then click Tags
. If you click on commit(s)
and it will take you to a screen where you can browse commits on different branches.
To learn more about git tag
, run git help tag
.
Graders:
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