What is the predicate function to determine if a given file is under version control? (I'm using git.)

4 Answers 4


The canonical way is to call (vc-backend <file>), AFAIK.


Try (vc-git-responsible-p (buffer-file-name)).

  • Thanks, that's 95% of the way there. The main hold-up is that it will incorrectly declare a file under version control if it is in a VC'd directory, even if the file itself is supposed to be ignored by VC. It's enough for my limited purposes, but let me leave the post open a bit longer to see if anyone can figure out the last little bit.
    – Dan
    Commented Jan 18, 2016 at 13:58
  • @Dan, follow up with vc-state
    – abo-abo
    Commented Jan 18, 2016 at 14:00
  • I think that does it, although the docstring suggests that vc-state could return nil, ignored, or unregistered for a non-VC'd file. Could you add the vc-state part to your answer? (By the way, that looks to be the VC system-agnostic answer.)
    – Dan
    Commented Jan 18, 2016 at 14:08

vc-registered is correct. You just pass it the file path and it will work with any backend. Use vc-responsible-backend to get the backend name.

(vc-registered (buffer-file-name))
;; => t

(vc-responsible-backend (buffer-file-name))
;; => Git
  • Precision from vc-responsible-backend docstring: "If FILE is already registered, return the backend of FILE. If FILE is not registered, then the first backend in `vc-handled-backends' that declares itself responsible for FILE is returned."
    – JeanPierre
    Commented Dec 16, 2016 at 20:55

These answers are wrong.

You should use (vc-git-registered (file)). Returns t or nil.

(vc-state (file)) returns state of repository. Not a state of a single file. vc-state returns 'up-to-date on file which is not under version control but it's located in directory which us under control of GIT.

  • vc-git-registered seems indeed a good choice if the VC is git, but how is using vc-backend wrong? What you say about vc-state is not what the docstring says, nor what the quick tests I did show.
    – JeanPierre
    Commented Mar 20, 2016 at 9:46
  • It's because vc-backend gives false results on GIT. It cannot see a difference between files added/staged to git but not commited. vc-backend returns nil on file which is staged already. Commented Mar 21, 2016 at 8:52
  • After tesing again, on emacs 24.4.1 both vc-state and vc-backend do recognize staged files.
    – JeanPierre
    Commented Mar 28, 2016 at 9: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.