How to save shell history from emacs and use it in terminal?
savehist-mode
isn't applicable here; the reason you're having this trouble is because Bash, by default, will only write to the history file when its in-memory history buffer is full or on exit, and the latter only if it exits cleanly -- that is, a Bash process which is killed rather than exiting will never write recent commands to the history file.
To work around the problem, ensure that you always cleanly finish your shell session by executing logout
or exit
, or typing C-d
at the prompt, before killing your shell buffers; this will give Bash a chance to write the history file before exiting.
Also, see the Bash FAQ on history file management, for some ideas on how to have Bash write each command to history as soon as it's executed; once you've gotten that working, you need no longer worry about logging out of your shells before you kill their buffers, but can C-x k
with wild abandon.