If I check out a tagged version of my source code without creating a branch, Git indicates that I’m not associated with any branch at all. It’s happy to let me make changes and check them in though. Where do those changes go? If I switch back to ‘master’ they disappear (overwritten by what was in master) and I can’t seem to find them again. What gives? If Git lets me commit changes against what’s essentially an anonymous branch, surely I can get them back?
Share
Because your commit isn’t on any branch, you can’t see it in the working directory unless you checkout that specific commit, using its SHA1. You can find the commit by looking at the
reflogwhich tracks changes in what you have checked out from the repo. If your tag wasXXXyou’ll see something like:That tells you the SHA1 that you would have to
checkoutin order to see your commit in the working directory.This all seemed a little weird to me at first, until I realized that git
checkoutplaces all the project files as of a particular commit into my file system (working directory). In effect, the working directory acts as a browser on the local Git repository. So your changes haven’t been overwritten in the repository, they’re just not being shown in your working directory when you’ve checked out the master.