What do git checkouts really mean?

As you noted, HEAD is a label noting where you are in the commit tree. It moves with you when you move from one commit to another. git checkout <commit> is the basic mechanism for moving around in the commit tree, moving your focus (HEAD) to the specified commit. The commit can be specified by … Read more

Restore file from old commit in git

git checkout ‘master@{7 days ago}’ — path/to/file.txt This will not alter HEAD, it will just overwrite the local file path/to/file.txt See man git-rev-parse for possible revision specifications there (of course a simple hash (like dd9bacb) will do nicely) Don’t forget to commit the change (after a review…)

Unstage a deleted file in git

Assuming you’re wanting to undo the effects of git rm <file> or rm <file> followed by git add -A or something similar: # this restores the file status in the index git reset — <file> # then check out a copy from the index git checkout — <file> To undo git add <file>, the first … Read more

Get back the changes after accidental checkout?

Another thing you can look at is through your IDE. I accidentally checkout 2 files and was able to bring back the changes through the ‘local history’ of my IDE (Netbeans). What a blessing! If you’re using Eclipse, do this by right clicking on the file and going to Team->Show Local History.