我正在尝试从功能分支切换到主功能而不会丢失我的更改,所以我正在尝试git stash
然后切换到主,但主人正在转移到我的功能分支.基本上:
<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??!!!
Run Code Online (Sandbox Code Playgroud)
我误解了git-stash吗?或者也许git作为一个整体?或者我是否误解了感知与现实的对应性?
更新
我刚发现它在a的情况下做同样的事情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....
Run Code Online (Sandbox Code Playgroud)
另一个更新
它只发生在回购的一个"实例"中(我不知道正确的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
Run Code Online (Sandbox Code Playgroud)
我曾经注意到类似的行为,当时我不小心创建了一个分支和一个名为 git 的标签,foo
并且 git 在内部按名称访问了一个提交并获取了错误的提交。
您是否可能不小心创建了一个名为master
或类似的标签?
还git reflog
应该显示正在发生的事情。