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?
相关问题
- Why does recursive submodule update from github fa
- Extended message for commit via Visual Studio Code
- Emacs shell: save commit message
- Can I organize Git submodules in a flat hierarchy?
- Upload file > 25 MB on Github
相关文章
- 请教Git如何克隆本地库?
- GitHub:Enterprise post-receive hook
- Git Clone Fails: Server Certificate Verification F
- SSIS solution on GIT?
- Is there a version control system abstraction for
- ssh: Could not resolve hostname git: Name or servi
- Cannot commit changes with gitextensions
- git: retry if http request failed
Yes, they'll be in reflogs.
You can name the branch at any time like this:
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
reflog
which tracks changes in what you have checked out from the repo. If your tag wasXXX
you'll see something like:That tells you the SHA1 that you would have to
checkout
in order to see your commit in the working directory.This all seemed a little weird to me at first, until I realized that git
checkout
places 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.Alternatively, you can merge the commit back into master without a new branch by finding its SHA1 (using git reflog as above) and then:
To answer the second question you'd use git reset --hard yourtagname
As for what would happen you essentially forked your branch at the tagname and stayed on the same branch. Your commits in the old fork are still there... they're just hard to see. You might have to use the reflog to find the old fork.