Git checkout HEAD won't discard my changes

Hello everyone,
I’ve been struggling with git checkout in the lesson ‘Learn Git’>‘How to backtrack’ here
The problem is, I do everything Codecademy asks me to do and it even lets me continue, but Git doesn’t discard my last change. It just doesn’t show.
I’ve made these commands:

$ git diff
diff --git a/scene-5.txt b/scene-5.txt
index fa75b29..5e2b9ef 100644
--- a/scene-5.txt
+++ b/scene-5.txt
@@ -13,5 +13,4 @@ I will.
 My hour is almost come,
-When I to sulphurous and tormenting flames
 Must render up myself.
$ git checkout HEAD "scene-5.txt"
$ ^C

But I still see this:

Hamlet: Act 1, Scene 5

Enter Ghost and Hamlet

Where wilt thou lead me? speak; I'll go no further

Mark me.

I will.

My hour is almost come,
Must render up myself.

Have you tried closing and reopening that particular file in the editor? If it was changed in the background it would need to be reloaded to clear whatever text is temporarily saved in the buffer (which is not the same as the saved version). Alternatively re-running git diff on that file should no longer show changes.


Thanks, re-opening worked!

1 Like