3

I am still very much a beginner when it comes to version control, and am using magit.

It seems like committing changes (frequently but not always?) triggers "reverting buffer" messages, one for each open buffer in the relevant repository. I panic every time I see one of these messages, thinking I lost the changes I just reviewed and/or committed. I don't really understand why there would be anything to revert. As far as I can tell my buffer should not have changed simply because I made a commit. I didn't kill a hunk, checkout a different branch or anything like that.

  • Assuming this sounds like normal behavior and not a bug related to my configuration, can someone explain what is happening?
  • And assuming its safe and reliable, is there a way to turn those messages off except when the buffer really has been changed?

1 Answer 1

7

Magit should only revert a file-visiting buffer if the file has actually changed on disk, see magit-revert-buffers. That function uses verify-visited-file-modtime to determine whether that is the case. Committing does not change any files, so you should not see any messages about files being reverted. Maybe something else, like e.g. a commit hook, is needlessly touching the files?

Reverting a buffer which doesn't need to be reverted isn't dangerous, but you will see the messages anyway.

3
  • Thanks @tarsius... If I understand, this means that anytime I save changes to a file, magit may revert the buffer to ensure that it reflects the state of the file. 1) Normally then the contents of the buffer will not change? (Assuming here that the saved changes were made in that buffer not somewhere else, like by another user.) 2) If the buffer and the file aren't identical, would magit warn me before it reverts?
    – Brian Z
    May 29, 2015 at 1:54
  • 1
    No. If you edit a file in Emacs and then save those changes, then Emacs knows that it itself made the change to the file. It records when it last saved the file. When it comes to checking whether something else changed the file afterwards it compares that time stamp with that recorded by the file system. Magit runs Git subprocess which may change files on disk. As far as Emacs is concerned these changes are made outside of Emacs (not by the emacs executable itself). This happens for example when you discard uncommitted changes or checkout another branch.
    – tarsius
    May 29, 2015 at 11:50
  • When using Magit's next branch, then you can configure it to always ask before reverting.
    – tarsius
    May 29, 2015 at 11:52

Your Answer

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

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