I have created a new repository and commited a file a.pl
. All ok.
If I do git status
that there is nothing added or untracked changes. I do a git log
and I see the hash
of my last (and actually only) commit in this repository.
Now I modify the a.pl
and I append a new line in the end of the file. E.g print "1";
I save it and if I do git status
it reports untracked changes.
Now If I do: git checkout <commit_id>
using the hash reported in git log
I expect to go to the version I commited, so my recent untracked modification should be deleted.
I do git checkout 1d739
and I get:
Note: checking out '1d739'.
You are in 'detached HEAD' state. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by performing another checkout. etc
When I look in the file, I see that the print "1";
I added is still there!
Now in this checkout version I append another line in the file: print "2";
and save the file.
Then I do: git checkout master
. This would take me back to the latest commit, right? So I expected that the last append I did print "2";
would be lost.
Well after I get: Switched to branch 'master'
I see the file and it has both print "1";
and print "2";
.
This is really confusing. Shouldn't I be seeing the latest commit now? And both the modifications should be lost?