Here is a grab-bag of stuff that works for me:
1) I break down my tasks (or at least the ones near the front of the queue) into chunks of at most two estimated hours, preferably just one. That way, if I'm staring at my screen and have a meeting (or end of day) in one hour, I can say "Hey, I said I could do this in one hour, let's prove it." We use scrum, which gives me a little more motivation because those tasks and estimates are public on a board.
2) If you use emacs, org-mode is really super for keeping track of stuff. It takes a while to learn, but it has saved my life at work. One particular thing it is good for is allowing me to shelve a distraction (say, an email I know I need to respond to) and know that I'll see it and come back to it later.
3) I have a little emacs function that I have bound to a key, which prompts me for a single line description of what I have just done, and appends it with a timestamp to the end of a given "diary" file. The descriptions can be as simple as this (a real sample):
08:16 Ready to look at #28614
08:48 Verified issue
08:50 AutoOn is false
08:57 Attemped fix
If I glance back at my diary file and see that there are big empty gaps in it, it's embarrassing, so it's a good motivation to keep working.
Here is my emacs function, if anyone is interested:
(defvar timestamped-note-file "c:/doc/diary.txt"
"File to store timestamped notes in.")
(defun register-timestamped-note (text)
(interactive "sNote: ")
(insert (concat (substring (current-time-string) 11 16) " " text "\n")))))