12

我正在尝试从功能分支切换到 master 而不会丢失我的更改,因此我尝试git stash然后切换到 master,但 master 正在移动到我的功能分支。基本上:

<feature*> $ git status
# On branch feature
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   modified:   hay.md
<feature*> $ git rev-parse --short HEAD
737b183 
<feature*> $ git rev-parse --short master
109b5f7 # This happens to be 4 commits ago
<feature*> $ git stash
Saved working directory and index state WIP on feature: 737b183 Some commit
HEAD is now at 737b183 Some commit
<feature> $ git rev-parse --short HEAD
737b183 
<feature> $ git rev-parse --short master
737b183 # WAT??!!!

我误解了 git-stash 吗?或者也许是整个 git?还是我误解了知觉与现实对应的本质?

更新 我刚刚发现它在git reset.

<feature*> $ git status
# On branch feature
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   modified:   hay.md
<feature*> $ git rev-parse --short HEAD
737b183 
<feature*> $ git rev-parse --short master
109b5f7
<feature*> $ git reset --hard HEAD
HEAD is now at 737b183 Some commit
<feature> $ git rev-parse --short HEAD
737b183 
<feature> $ git rev-parse --short master
737b183 # Hm....

另一个更新

它只发生在 repo 的一个“实例”中(我不知道正确的 git 词汇),所以我想.git/. 一个创可贴的解决方案是删除 repo 并再次从远程克隆它,但我有点想知道它为什么会发生。

还有一些东西

‹master› » git checkout feature
Switched to branch 'feature'
Your branch is ahead of 'master' by 1 commit.
  (use "git push" to publish your local commits)
‹feature› » echo "Hay" >> hay.md
‹feature*› » cat .git/HEAD
ref: refs/heads/feature
‹feature*› » cat .git/refs/heads/master
93d9d14b0f298ed28cc1520905768281f32d0929
‹feature*› » cat .git/refs/heads/feature
51410c5dcd679b8cf57a7dce2d17be7bbd121923
‹feature*› » git stash
‹feature› » cat .git/HEAD
ref: refs/heads/feature
‹feature› » cat .git/refs/heads/master
51410c5dcd679b8cf57a7dce2d17be7bbd121923
‹feature› » cat .git/refs/heads/feature
51410c5dcd679b8cf57a7dce2d17be7bbd121923
4

1 回答 1

1

当我不小心创建了一个分支和一个名为的标签时,我曾经注意到类似的行为,foo而 git 在内部按名称访问了一个提交并采取了错误的提交。

您是否可能不小心创建了一个名为master或类似的标签?

git reflog应该显示正在发生的事情。

于 2013-11-08T16:35:57.297 回答