Skip to content

Commit

Permalink
tags
Browse files Browse the repository at this point in the history
  • Loading branch information
miallo committed Jan 3, 2024
1 parent 8912128 commit ebff879
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
8 changes: 8 additions & 0 deletions create_challenge.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ sed "s/BRANCH_COMMIT/$BRANCH_COMMIT/" "$DOCDIR/03_commit/commit.md" > commit.md
git add commit.md
commit -m "Add description on commit"

git switch --detach @
cp "$DOCDIR/08_tags/tags.md" .
git add tags.md
commit -m 'Add description on tags
Flag: LogCat'
git tag -a the-first-tag -m "Flag: AnnotateMeIfYouCan"

git switch main -c history
cp "$DOCDIR/06_log/log.md" .
git add log.md
Expand Down
9 changes: 9 additions & 0 deletions src/08_tags/tags.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Tags

A tag is (like a branch) a human readable way to refer to a specific commit. The difference is that a tag "stays attached" to that commit, even if you check it out and create a new commit (whereas the branch would be updated to point to the new commit). That means that they are useful to tag releases.

When simply trying to switch to a tag with `git switch the-first-tag` you will get an error:
> hint: If you want to detach HEAD at the commit, try again with the --detach option.
so you need to run `git switch --detach the-first-tag` instead. Why? This is gits way to warn you that you could loose work when you start working and then commit your work, since you don't have a simple way to refer to that commit later, because it does not have a "nice name".

Is that bad? No, not at all - you just have to keep this in mind. And even if you create a new commit while being in a detached HEAD state and you switched back to a different branch, there are ways to recover it - but that will be a story for later ;)
7 changes: 7 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,11 @@ git switch branches-explained 2>&1 | grep --quiet "Flag: Switcheridoo"
echo 'MyFirstBranch when creating'
git switch -c my-new-branch 2>&1 | grep --quiet "Flag: MyFirstBranch"

git switch history
echo 'LogCat for log'
exec $(sed -n '/^```sh$/,/^```$/{n;p;}' log.md) | grep --quiet "Flag: LogCat"

echo 'AnnotateMeIfYouCan in annotated tag'
git show the-first-tag | grep --quiet "Flag: AnnotateMeIfYouCan"

echo success!

0 comments on commit ebff879

Please sign in to comment.