gpt4 book ai didi

git-stash 正在移动我的主分支

转载 作者:IT王子 更新时间:2023-10-29 00:49:33 29 4
gpt4 key购买 nike

我试图在不丢失更改的情况下从功能分支切换到 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/ 中有一些奇怪的东西。创可贴解决方案是删除存储库并再次从远程克隆它,但我很想知道为什么会发生这种情况。

一些东西

‹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

最佳答案

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

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

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

关于git-stash 正在移动我的主分支,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19821560/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com