first-tag という名前のタグがあるとします。
git
$ git tag
first-tag
また、first-tag という名前のファイルも存在しており編集中です。
まだコミットはされていません。
git
$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: first-tag
no changes added to commit (use "git add" and/or "git commit -a")
この状態のとき、first-tag ファイルをチェックアウトする(編集を取り消し)にはどうすればよいでしょうか。
もし、単純にファイル名を指定してチェックアウトしてみると。
git
$ git checkout first-tag
error: Your local changes to the following files would be overwritten by checkout:
first-tag
Please commit your changes or stash them before you switch branches.
Aborting
このようにタグをチェックアウトしようとする動作になり、怒られてしまいます。
こういったケースでは、-- (bare double dash) を使って、チェックアウトしたいのはファイルであることを明示してあげる必要があります。
git
$ git checkout -- first-tag
$ git status
On branch master
nothing to commit, working tree clean
# もちろんタグは残っています
$ git tag
first-tag