As far I know git checkout doesn't allow us to checkout branch until we commit all the previous changes but my changes have been discarded.
I executed git status command and it showed me the list of modified files.
Then I executed git checkout . (dot) command but it didn't prompt me to first commit my previous changes and discarded all my changes and checked out master branch on my local machine.
Can anyone please guide me that why git checkout . behaved in this way?
And how I can move back to my previous code on my local machine (with modified and uncommitted changes)? Why did it discard my changes?
Unfortunately, git checkout is a command that has several very different meanings, and this has caused your problem: with checkout you can switch branches, create a branch, update your working directory files with a specific version or the HEAD of a branch.
When you do: git checkout <branchname>, you ask git to switch branch, so it will warn you if you have uncommitted changes that you can remove, stash or commit.
When you do: git checkout <pathname>, you ask git to update your files with a version, so you ask git to override potential modifications with what is already in the repository; which is what git did.
Hope it'll help. Sorry for your discarded changes. This is where the simplicity of a UI is important.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With