无法回到我最近的提交(或其中任何一个)

时间:2017-02-28 19:21:44

标签: git

  

编辑:我在cd ..git checkout master之后收回了我的文件。

     

奇怪的是,这几乎看起来像是在子文件夹templates中初始化了一个新的存储库,但我看不出我做了那样的命令。不过,我仍然不知道出了什么问题。

我在自己的项目中使用Git大约一个月,工作得非常好。

然而,今天,我无法返回我的文件。老实说,我不知道为什么。我做了一些提交,然后我想检查一些早期的提交,所以我在提交时做了git checkout,我得到了那个提交。然后我使用相同的命令再往前走了一会儿。我尝试使用git checkout master回到我最近的提交,由于某种原因,该提交无效。然后我尝试git checkout head,认为这是命令。

然后我四处搜索并获得了一些关于其他一些命令的提示,这可能是一个糟糕的建议。很高兴这只是我自己的项目。

我现在觉得有点卡住,做不了多少,我不敢再尝试了。你能帮助我吗?

自从我上次提交以来,我已将ouputfrom终端包含在此处,因此您可以查看所有信息。很抱歉推了这么多,但我几乎不知道出了什么问题。

➜  templates git:(hello_templates) ✗ gc
[hello_templates 258d27a] add rot13-page
 5 files changed, 44 insertions(+), 2 deletions(-)
 create mode 100644 appengine/standard/templates/rot13.py
 create mode 100644 appengine/standard/templates/templates/rot13.html
➜  templates git:(hello_templates) ✗ gloh
zsh: command not found: gloh
➜  templates git:(hello_templates) glog
➜  templates git:(hello_templates) git checkout 615f292
Note: checking out '615f292'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, 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 615f292... Crappy hard-coded bullshit
➜  templates git:(615f292) glg
➜  templates git:(615f292) glog
➜  templates git:(615f292) git checkout 076887a
Previous HEAD position was 615f292... Crappy hard-coded bullshit

HEAD is now at 076887a... Made form with validation, html-escaping and redirection
➜  templates git:(076887a) git checkout master
Switched to branch 'master'
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)
➜  templates git:(master) gst
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)
nothing to commit, working tree clean
➜  templates git:(master) git checkout head
Note: checking out 'head'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, 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 076887a... Made form with validation, html-escaping and redirection
➜  templates git:(076887a) glog
➜  templates git:(076887a) git checkout heada
error: pathspec 'heada' did not match any file(s) known to git.
➜  templates git:(076887a) git checkout head
HEAD is now at 076887a... Made form with validation, html-escaping and redirection
➜  templates git:(076887a) git branch
* (HEAD detached at head)
  hello_templates
  master
➜  templates git:(076887a) git checkout HEAD
➜  templates git:(076887a) git branch
* (HEAD detached at head)
  hello_templates
  master
➜  templates git:(076887a) gst
HEAD detached at head
nothing to commit, working tree clean
➜  templates git:(076887a) git checkout master
Switched to branch 'master'
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)
➜  templates git:(master) git branch
  hello_templates
* master
➜  templates git:(master) glog
➜  templates git:(master) owd
zsh: command not found: owd
➜  templates git:(master) pwd
/Users/runarkristoffersen/dropbox/Data/cources/FullStack/googleapps/python-docs-samples/appengine/standard/templates
➜  templates git:(master) gco 615f292
error: pathspec '615f292' did not match any file(s) known to git.
➜  templates git:(master) ✗ git checkout HEAD^
error: pathspec 'HEAD^' did not match any file(s) known to git.
➜  templates git:(master) ✗ git checkout -
error: pathspec '-' did not match any file(s) known to git.
➜  templates git:(master) ✗ git reflog
fatal: your current branch 'master' does not have any commits yet
➜  templates git:(master) ✗ git checkout $(git log --branches -1 --pretty=format:"%H")
fatal: your current branch 'master' does not have any commits yet
fatal: You are on a branch yet to be born
➜  templates git:(master) ✗ gb
➜  templates git:(master) ✗ git branch
➜  templates git:(master) ✗ glog
fatal: your current branch 'master' does not have any commits yet

1 个答案:

答案 0 :(得分:2)

  

奇怪的是,这几乎看起来像是在子文件夹模板中初始化了一个新的存储库,但我看不到我做了这样的命令。

您要么初始化一个新的仓库(寻找templates/.git子文件夹)。

或模板被声明为 submodule 。查找.gitmodules in的一个template个父文件夹。

  

我在.git

中找到了templates-folder

这会使templates-folder成为嵌套的git repo,这会使其父代repo只记录 gitlink (而不是文件夹内容)

删除.git子文件夹以及git add templates-folder足以让我们回到正轨。