Without path of files, what exactly does
git checkout commit-sha
do ?
Anyone can explain it to me?
Without path of files, what exactly does
git checkout commit-sha
do ?
Anyone can explain it to me?
Git will attempt to check out the given commit, as what Git calls a detached HEAD.
As with any git checkout
, the operation may succeed, or may fail. The main reason for a failure is an attempt to check out some other commit when you have uncommitted work.
Checking out some other commit / other branch when you do have uncommitted work sometimes succeeds. The explanation for this apparent discrepancy is in Checkout another branch when there are uncommitted changes on the current branch.
If the checkout succeeds, you have a detached HEAD, and your index and work-tree have been filled from the target commit. As noted in the linked question and answer, if you have uncommitted changes, they have been preserved: in this case at least some index and work-tree files do not match the selected commit.