The history in mostly controlled by shell parameters.

HISTCONTROL

HISTCONTROL is one of these parameters.

Here is what man bash says:

HISTCONTROL A colon-separated list of values controlling how commands are saved on the history list. If the list of values includes ignorespace, lines which begin with a space character are not saved in the history list. A value of ignoredups causes lines matching the previous history entry to not be saved. A value of ignoreboth is shorthand for ignorespace and ignoredups. A value of erasedups causes all previous lines matching the cur‐ rent line to be removed from the history list before that line is saved. Any value not in the above list is ignored. If HISTCONTROL is unset, or does not include a valid value, all lines read by the shell parser are saved on the history list, subject to the value of HISTIGNORE. The second and subsequent lines of a multi-line compound command are not tested, and are added to the history regardless of the value of HISTCONTROL.

Type echo $HISTCONTROL to see how it is set for you.

ignoredups - ignore same commands following eachother

- ignore same commands following eachother ignorespace - ignores commands beginning with space as you said

- ignores commands beginning with space as you said ignoreboth - both of the above

- both of the above erasedups - delete old commands when they are used again

My guess is that you have erasedups enabled and commands are missing, because they have been reused at a later point.

HISTIGNORE

It is also possible to completely ban certain commands or patterns from appearing in the history.

Type echo $HISTIGNORE to see which are banned for you. The list of patterns is separated by colons : . It is also possible to ban a pattern like history* would ban all commands starting with the word history.

Disabled history

Also the history can be disabled althogher.

If none of these cases applies to you, you could clarify your question, by adding a sequence of commands not fully preserved in the history.