0

I initialized a Git repository outside emacs, added and committed the files.

Now if I a file in emacs that is under version control by Git and run C-x v = emacs tells me This file is not under version control.

It seems emacs missed that I added this file to Git already. How can I tell emacs that this file (and the whole directory) is already in Git, so that I can use the vc-git-* commands?

  • You're mixing your terminology up. By "open a buffer" do you mean "visit a file" (not already visited) or "switch to a buffer" (of an already-visited file)? – phils Oct 27 '16 at 5:10
  • @phils I edited for clarity, I mean opening a file in emacs (that was already existing and added to Git). – Max Oct 27 '16 at 6:11
  • I can't replicate the problem. Which version of Emacs are you using, on which OS? You might also check whether M-: (executable-find "git") knows where your git binary lives -- the relevant directory needs to be listed in C-h v exec-path. – phils Oct 27 '16 at 8:03
  • Git works without any issues for other files in different project directories, I am using Emacs on OS X in version 24.5.1 – Max Oct 27 '16 at 8:15
  • 1
    Hm I feel a bit dumb now, but closing the buffer and opening it again fixed the problem, now vc- commands work as I would have expected. Sorry for the noise. :-( – Max Oct 27 '16 at 8:51
1

Emacs caches version control information for each buffer.

If you visit a file first, and then git add it in a terminal, Emacs doesn't know this. You can M-x revert-buffer to force it to refresh the cache, or kill the buffer and visit the file again.

In the future, you can register such files from within Emacs, using vc-next-action, by default bound to C-x v v. Though if the file is already registered this command will do something else.

  • Instead of vc-next-action (which would indeed do something else if the file is already registered), why not vc-register? ( C-x v i ) – T. Verron Oct 27 '16 at 12:41
  • @T.Verron Thas is indeed a good alternative. I don't recall ever using it, though (it's a bit easier to remember just one key sequence). – Dmitry Oct 27 '16 at 13:57
  • I agree that in a standard workflow (e.g. if the file was just created), vc-next-action should be what you want. And anyway, even if it wasn't just created, I guess if the user wants to register the file, he would want to commit it anyway (which should be the result of vc-next-command in that case, iirc). – T. Verron Oct 27 '16 at 14:11
  • Thank you for the explanation, I was a bit confused by the observed behaviour. C-x v i sounds like a good thing to remember. – Max Oct 29 '16 at 1:06
1

After update of MacOS (10.14.6) I had the same "This file is not under version control" - turns out that I needed to accept xcode license to run git commands.

In terminal just do a sudo xcodebuild -license- that fixed my problem.

  • 1
    Git is Free Software, so you should not need to accept any license to run it. I recommend you complain to Apple about it. Also you might like to install Git separately from Xcode, which might avoid the problem. – Stefan Sep 26 at 12:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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