Is there a way to exclude .git/COMMIT_EDITMSG files from file-name-history? Now that I'm authoring commits with Magit, those commit message files are often the most recent entries in file-name-history, which is annoying since they're never what I'm looking for when scrolling through history entries.

  • Are you sure you mean file-name-history and not recentf-list? If it is the latter, then you can use recentf-exclude. On the other hand git-commit.el already includes (eval-after-load 'recentf '(add-to-list 'recentf-exclude git-commit-filename-regexp)), so you shouldn't have to.
    – tarsius
    Commented Sep 20, 2016 at 17:10
  • Only files that you actually select when using find-file and such should be added to file-name-history (I think). Do you do that? Why?
    – tarsius
    Commented Sep 20, 2016 at 17:12
  • @tarsius I haven't used find-file on a COMMIT_EDITMSG file, but when I use find-file and hit M-p (previous-history-element), there's usually a COMMIT_EDITMSG in there. To confirm, I first deleted it from file-name-history, inspecting the variable to ensure it was gone. Then I used Magit to author a commit, and inspecting file-name-history again showed it back in there.
    – ivan
    Commented Sep 20, 2016 at 18:14
  • Hm, maybe my assumptions about when something gets added to file-name-history are wrong.
    – tarsius
    Commented Sep 20, 2016 at 18:38
  • server-visit-files adds the file to file-name-history. I don't see any way to prevent that short of advising that function.
    – tarsius
    Commented Sep 20, 2016 at 19:01

1 Answer 1


These files (COMMIT_EDITMSG, git-rebase-todo and others) are added to file-name-history by server-visit-files. It is possible to undo that by advising that function, and I have implemented that.

But I am unsure whether that advise should also remove entries for these files that already existed prior to that function being called. I think so because those entries are very likely there from before this advice was added. On the other hand this might surprise users who, for whatever reason, edit these files by manually opening them. I'll decide at a later time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.