0

不久前,我检查了之前的提交,然后再次检查了我最近的提交。当时我并没有意识到这一点,但这让我处于一种超然的头脑状态。从那时起,我已经完成了多次提交,并且仍然处于分离的头部状态。我知道我可以通过做来摆脱这种状态git checkout <branch name>,但如果我这样做,我会失去什么吗?

4

1 回答 1

1

I can get out of this state by doing git checkout <branch name>, but if I do this will I lose anything?

Yes, you will lose all the commits you've made in detached head mode, because no branch name will be pointing to them. (You won't totally lose them immediately, but they will be slated for destruction, and accessing them will become more difficult.)

So simply create a branch first, to retain them and give you a way to refer to them.

git switch -c temp

Now it's safe to checkout branchname.

Actually in your case, though, since your HEAD is in fact where you wish your branch was, you can just move your branch name to where you are now instead. No need for temp at all.

git switch -C branchname 
于 2022-03-04T05:55:05.287 回答