我正在尝试从功能分支切换到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....
另一次更新
它只发生在回购的一个“实例”中(我不知道正确的git词汇),所以我想在.git/
中有一些不可思议的东西。一个bandaid解决方案是删除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
答案 0 :(得分:1)
当我意外地创建一个名为foo
的分支和标记时,我曾经注意到类似的行为,而git在内部通过名称访问了一个提交并且使用了错误的一个。
您是否可能意外地创建了一个名为master
的标签或类似的标签?
同样git reflog
应该显示正在发生的事情。