意外と知られていない気がしたのでブログにします。便利です。
環境
- Git Bash
- GNU bash, version 4.4.23(1)-release
方法
ブランチを変更するGitコマンド、switch
とcheckout
にブランチ名ではなく-
を設定すると直前のブランチに移動できます。なお、この-
は@{-1}
の省略形です。@{-2}
等を指定することで、2つ前に戻ることも可能ですが、私は-
しか使用したことはありません。
# 直前(1個前)のブランチに戻る git switch - git checkout - # 2個前のブランチに戻る git switch @{-2}
ヘルプ原文の記述。
You can use the @{-N} syntax to refer to the N-th last branch/commit switched to using "git switch" or "git checkout" operation. You may also specify - which is synonymous to @{-1}. This is often used to switch quickly between two branches, or to undo a branch switch by mistake.
その他
cd
コマンドでも-
で直前のディレクトリに移動できます。こちらも覚えると非常に便利です。
終わりに
たまにTwitterで流れてくるネタですのでブログにしてみました。便利なので私個人は忘れないでしょうが、この記事を見て知った人がいれば幸いです。