问题
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