1
messense 2014-10-05 12:42:46 +08:00 1
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this state without impacting any branches by performing another checkout. If you want to create a new branch to retain commits you create, you may do so (now or later) by using -b with the checkout command again. Example: git checkout -b new_branch_name 不是新分支...你想做的是 git reset commit_id 吧? |
2
billlee 2014-10-05 12:47:54 +08:00 2
这个状态还不算是一个新分支吧,叫做 detached 状态。如果你这时做了个 commit, 那么这个 commit 就是属于一个新分支的,但如果不给这个新分支命名,然后又 checkout 了其他分支,那么这个新分支的引用计数就变为0了,会被回收。
在新版本的 git 里应该是这样提示的: You are in 'detached HEAD' state. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by performing another checkout. If you want to create a new branch to retain commits you create, you may do so (now or later) by using -b with the checkout command again. Example: git checkout -b new_branch_name |
4
ceyes 2014-10-05 14:32:18 +08:00 1
这相当于开了个“临时分支”, `git branch` 看一下就明白了
要恢复的话用`git reset <id>` (注:默认是 --soft, 当前的改动还在,想完全回到之前加 --hard) |
5
jsfaint 2014-10-05 16:48:32 +08:00 1
git checkout hashid是切换workspace到一个已提交的commit
git checkout -b hashid才是创建一个新分支并checkout 楼主reset的话,可以 git reset hashid --hard就会丢掉hashid这个commit之后所有的修改(慎用!) |
6
zix 2014-10-06 16:04:00 +08:00
按你的意思,你需要reset,不过慎用--hard就是了(--soft或者--mixed都可以),附一个链接:
http://marklodato.github.io/visual-git-guide/index-zh-cn.html |
7
billlee 2014-10-06 20:13:33 +08:00
如果想要谨慎一点,可以先 git branch hold, 再做 git reset. 这样会在 master 分支上把 commits 丢弃,但新开的 hold 分支还是原来的样子。确认无误后再 git branch -D hold.
|
8
hww 2014-10-07 11:10:05 +08:00
git checkout -b "新分支名称"
|