I have written a small function in Emacs that does a
git stash git stash apply
in the Git repository of the file I visit, and I have added this function in after-save-hook so it runs every time I save the file. The problem is that when I save the file, the git commands above run and change the timestamp, so Emacs thinks that the file has been modified outside Emacs itself. Naturally, when I try to edit the file again (without closing and re-opening) Emacs asks if I want to really edit the buffer which is quite annoying.
Any ideas on how to make Emacs not think that the file has been changed as a result of the above git commands?
EDIT: Thanks jvasak. Adding (revert-buffer nil t t) at the end of my function did the trick.
I don’t know for sure that this would work, but you could add
revert-bufferto yourafter-save-hookwhich should reload the file from disk. Combined with therevert-without-querytrick from the GNU Emacs Manual, this may provide the desired behavior.