Pau*_*aul 79
因为您的提交不在任何分支上,所以除非您使用其SHA1签出该特定提交,否则您无法在工作目录中看到它.您可以通过查看reflog
从回购中检出的内容的变化来查找提交.如果你的标签是XXX
你会看到类似的东西:
$ git reflog
7a30fd7... HEAD@{0}: checkout: moving from master to XXX
ddf751d... HEAD@{1}: checkout: moving from 96c3b0300ccf16b64efc260c21c85ba9030f2e3a to master
96c3b03... HEAD@{2}: commit: example commit on tag XXX, not on any branch
7a30fd7... HEAD@{3}: checkout: moving from master to XXX
Run Code Online (Sandbox Code Playgroud)
这告诉你checkout
为了在工作目录中看到你的提交你必须使用SHA1 .
$ git checkout 96c3b03
Note: moving to "96c3b03" which isn't a local branch
If you want to create a new branch from this checkout, you may do so
(now or later) by using -b with the checkout command again. Example:
git checkout -b <new_branch_name>
HEAD is now at 96c3b03... example commit on tag XXX, not on any branch
$ git checkout -b newbranch
$ git branch #lists all branches
feature1
master
* newbranch
Run Code Online (Sandbox Code Playgroud)
这一切对我来说似乎有点奇怪,直到我意识到git checkout
将所有项目文件作为特定提交放入我的文件系统(工作目录).实际上,工作目录充当本地Git存储库上的浏览器.因此,您的更改尚未在存储库中被覆盖,当您检出主服务器时,它们只是没有显示在您的工作目录中.
是的,他们将在reflogs中.
您可以随时命名分支,如下所示:
git checkout -b my-branch-name
Run Code Online (Sandbox Code Playgroud)
或者,您可以通过查找其SHA1(使用上面的git reflog)将提交合并回master而不使用新分支,然后:
git checkout master
git merge SHA1
Run Code Online (Sandbox Code Playgroud)