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のhistory履歴を保存できるようにした

Last updated at Posted at 2025-04-13

本記事の背景

Linux環境において、historyはデフォルトで自動的に保存されるように設定されているが、
VSCODE+Git Bash for windowsを使う場合、VSCODEを再起動する度、履歴はクリアされてしまうので、少し不便である。本記事はこれを解消できる以下に手順を示す

解消手順

  1. ホームディレクトリに .bashrc を作成(または編集)
  2. 履歴の設定を .bashrc に追加
  3. .bash_profileを編集
  4. Git Bash を再起動 or source ~/.bashrc で反映
  5. VS Code のターミナルで Git Bash を使う設定が正しいか確認

詳細

履歴の設定

nano .bashrc 
# ~/.bashrc に追記する内容

# 履歴ファイルの場所
HISTFILE=~/.bash_history

# history にタイムスタンプを記録する(epoch形式 or フォーマット付き)
HISTTIMEFORMAT="%F %T "

# 履歴に保存するコマンド数
HISTFILESIZE=10000
HISTSIZE=10000

# セッション中の履歴を即時保存
PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND"

bash profileの編集

nano .bash_profile
# ~/.bash_profile に追加(または修正)

if [ -f ~/.bashrc ]; then
  . ~/.bashrc
fi

設定を有効にする

. .bashrc

最後にVSCODEを再起動し、ターミナルでhistoryコマンドを確認し、保存されていることを確認する

結果

history
    1  2025-04-13 11:10:26 cd game-by-pyglet/
    2  2025-04-13 11:10:26 python move_char.py
    3  2025-04-13 11:10:26 python main.py
    4  2025-04-13 11:10:26 python auto_move_char.py
    5  2025-04-13 11:10:26 touch main_app.py
    6  2025-04-13 11:10:26 python main_app.py
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?