Say, I got ~/.emacs which is a soft link to ~/.emacs.d/init.el(using ln -s ~/.emacs.d/init.el ~/.emacs) which is in a git repo, because this will make it easier to reach init.el, outside or inside Emacs.

When I edit the file using bookmarks(bookmark for ~/.emacs not ~/.emacs.d/init.el) or C-x C-f to ~/.emacs directly, it will only edit the link, I use (setq vc-follow-symlinks 'nil) to not prompt to ask yes/no and not follow to the real file, (e.g., M-: (buffer-file-name) shows the /home/user/.emacs not /home/user/.emacs.d/init.el).

But sometimes I want to show the diff of this file, the C-x v = will not work for the link, it works in the file if I follow the link to it or open ~/.emacs,d/init.el directly. I don't want to do M-x magit-status and then ~/.emacs.d/ repo and then find the init.el and then TAB, so is there an easy way to show the diff of the file??

  • 4
    I don't really understand why you disabled vc-follow-symlinks (or why you are maintaining the ~/.emacs path at all, for that matter -- if it's purely for convenience, this is probably more useful?).
    – phils
    Commented Nov 18, 2014 at 5:27
  • It's purely for convenience, no special reason. Anyway @ph0t0nix 's answer solve this problem.
    – CodyChan
    Commented Nov 18, 2014 at 13:30
  • Have you seen my answer? Doesn't it make sense to you? I am happy to clarify. Otherwise please accept it.
    – tarsius
    Commented Mar 11, 2015 at 10:23

2 Answers 2


I had the same problem and added

;;; When opening a file that is a symbolic link, don't ask whether I
;;; want to follow the link. Just do it
(setq find-file-visit-truename t)

to my .emacs file.

Unfortunately I can't remember where on the web I found this, so no source credits.


It's really quite simple; don't do that:

I use (setq vc-follow-symlinks nil) to not prompt to ask yes/no and not follow to the real file

It doesn't make much sense to set this variable to nil and find-file-visit-truename to t. Both variables control whether Emacs should follow symlinks when visiting files. But the latter is much more aggressive. vc-follow-symlinks only has an effect if the file itself is a symlink, while find-file-visit-truename follows any symlink leading up to the file, i.e. if a ancestor directory is a symlink it follows that too.

The latter is more expensive and likely not what you want. find-file-visit-truename overrides whatever you have set vc-follow-symlinks to, and then it may also go on following other symlinks. If setting the latter to t gets the job done, then it's preferable to do just that.

Since you mentioned that you have set vc-follow-symlinks to nil I assume that you don't want to follow symlinks. But there's just no way around it. Like a shell an Emacs buffer has a "working directory", stored in default-directory. That variable is, among other things, used when running child processes (git in the case of VC and Magit). Without following the symlink, the process would be run with a working directory which is not inside a repository.

Or in other words:

How to make vc-* and magit treat a soft link to a real file in git repo just like the original file?

You can't because default-directory is set based on the filename. Instead follow the symlink and thereby move into the repository.

  • @CopyChan I have updated my answer.
    – tarsius
    Commented Jan 5, 2015 at 1:31
  • @ph0t0nix you might want to have a look too.
    – tarsius
    Commented Jan 5, 2015 at 1:33

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.