我正在尝试从功能分支切换到 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