.bash_history does not update in Git for Windows (git bash)

大兔子大兔子 提交于 2019-12-18 11:07:21

问题


I am using Git for Windows (ver. 1.7.8-preview20111206) and even though I have a .bash_history file in my HOME folder, it never automatically gets updated. When I start Git Bash, I can see in the history commands that I manually added to the .bash_history file, but it does not get updated automatically.

I used the shopt -s histappend command to make sure that the history gets saved every time I close the shell, but it does not work.

If I manually use the history -w command, then my file gets updated, but I would want to understand why the shopt command does not work as I understand it should.

Anyone can tell me why is this behavior happening?

Thanks in advance


回答1:


I put this in my ~/.bash_profile

PROMPT_COMMAND='history -a'



回答2:


As it was said here, to save git bash history on Windows you must not close the terminal with X button. Use exit command instead. History of commands will be saved then regardless of configuration mentioned in the accepted answer.




回答3:


If you use git bash for windows 8, just put this in your ~/.bash_logout file:

history > .bash_history

Obviously you need a ~/.bash_history file.

Regards.




回答4:


If you're using Git bash in VSCode please see C.M.'s comment above.

This worked for running git's bash in Visual Studio Code, but I had to put it ~/.bashrc not ~/.bash_profile. – C.M. Jul 29 at 14:43

This solved it for me.



来源:https://stackoverflow.com/questions/10488498/bash-history-does-not-update-in-git-for-windows-git-bash

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!