Command to show difference between a buffer and its corresponding file

EmacsDiff

Emacs Problem Overview


Is there an emacs command to show the difference between a buffer and its file?

For example, I've made some edits to a buffer, forgotten what they were, and now I need to save the buffer to its file, but want to check what I have actually changed first.

Emacs Solutions


Solution 1 - Emacs

diff-buffer-with-file. I just googled for "emacs compare buffer file changed".

Solution 2 - Emacs

Another option is to hit C-x s followed by d. This also shows a diff between a buffer and its file.

Most useful if the buffer of interest is the only one that needs saving.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionbphView Question on Stackoverflow
Solution 1 - EmacschorobaView Answer on Stackoverflow
Solution 2 - EmacsbphView Answer on Stackoverflow