【发布时间】:2014-08-25 09:55:17
【问题描述】:
我需要切换到较旧的提交以检查我们程序的较旧功能,该功能后来已被删除。
为此,我检查了相应的提交:
git checkout 367af0345d0b09ab3ade1c7856462f68e5eafe86
然后我更改了一些有关此已弃用功能的代码。但这只是为了检查我想忽略所有这些。
现在验证完成我想回到最新的工作代码:
git checkout master
但不幸的是,我收到了一个听起来很糟糕的警告:
git checkout master
Checking out files: 100% (281/281), done.
Warning: you are leaving 183 commits behind, not connected to
any of your branches:
367af03 message
e5eee29 message
6999d77 message
... and 179 more.
If you want to keep them by creating a new branch, this may be a good time
to do so with:
git branch new_branch_name 367af0345d0b09ab3ade1c7856462f68e5eafe86
Switched to branch 'master'
确实我想保留最近的 183 次提交,但我不想创建新分支,只是暂时恢复到我之前的状态......
问题是,现在这 183 个提交实际上存在于我的代码中,因此它们并没有像警告所暗示的那样丢失。
我错过了什么?
【问题讨论】:
-
(1) 你最初是怎么想到
367af0345d0b09ab3ade1c7856462f68e5eafe86的? (2) 如果您尝试git branch --contains 367af0345d0b09ab3ade1c7856462f68e5eafe86和git tag --contains 367af0345d0b09ab3ade1c7856462f68e5eafe86,是否其中任何一个打印一些东西?警告意味着至少branch --contains输出必须为空... -
我在 github 上以图形方式提出了这个提交哈希。两个git分支
return* master`和git标签输出为空。 -
那很奇怪:如果
367af03...包含在master中,git checkout不应该抱怨,应该只是说它正在移动到master并且之前的 HEAD 是在那个 SHA-1 处分离。
标签: git git-checkout revert