LoginSignup
0
0

More than 3 years have passed since last update.

git 同じ名前のタグとファイルが存在する場合

Posted at

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
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0