0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

VSCodeのgit bashのコマンド履歴が残らない原因と対策

Posted at

テーマ

VSCodeのターミナルで実行したGit Bashのコマンド履歴が残らなくて困ったので、問題の原因と解決策について調査しました。

原因

  • ターミナルの終了方法:
    いつもexitコマンドを使用してターミナルを終了していなかったので、git bashが正常終了せず、コマンド履歴の保存処理が行われなかったからでした。

解決策

  • コマンド履歴の保存タイミングの設定を変更する:
    .bashrcファイルに以下の行を追加します。この設定により、コマンド実行後に履歴が自動的に保存されます。

    shopt -s histappend
    PROMPT_COMMAND="history -a; $PROMPT_COMMAND"
    

補足

  • git bashのコマンド履歴保存のデフォルトの仕様

    AIのFelo先生によると、デフォルトでは以下とのこと。

    • コマンド履歴は~/.bash_hisotory に保存される。
    • git bashが正常終了したときのみ保存される。

参考

以下の記事を参考にしました。ありがとうございました。
https://qiita.com/hogeco/items/192d933c4290580238c7
https://qiita.com/misohagi/items/3ab0abc3bce2c11719c8
https://qiita.com/ko-zi/items/7563cae9d336626c3637

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?