What happened if I hadn't added a period at the end of `git checkout [commit]`?
I would like to view a previous version of the code. And select the command git checkout [commit]
to return the workspace to the target version.
I tried both git checkout [commit]
and git checkout [commit] .
. With or without a tail point, the workspace can be folded back.
So what's the difference between them?
source to share
The difference is very simple and inherent in how git thinks.
git branch
* master
git checkout [commit]
git branch
* (no branch)
git status
<no changes>
Here you asked git to switch to an unnamed branch based on [commit]. He did it and you have a clean working directory ready for you to name your branch. will send you home again. git checkout master
git branch
* master
git checkout [commit] -- .
git branch
* master
git status
<lots of changes>
Here you asked git to fetch the contents of [commit] and sprinkle them all over the working directory, ready for you to do whatever you want with the files. ' ' will send you home again. git reset --hard HEAD; git clean -f -d -x
source to share