您当前的位置: 首页 > 学无止境 > 心得笔记 网站首页心得笔记
12 分离头指针情况下的注意事...
发布时间:2020-07-11 14:47:27编辑:雪饮阅读()
从某个提交中检出(头指针分离)
xy@DESKTOP-BG9HNHK MINGW64 ~/Desktop/web/web2 (master)
$ git log
commit 8d69518fc3ba3ee5a60d90ed7f61d020d59cde0d (HEAD -> master)
Author: 雪饮 <1509272975@qq.com>
Date: Sat Jul 11 10:28:00 2020 +0800
add readme
xy@DESKTOP-BG9HNHK MINGW64 ~/Desktop/web/web2 (master)
$ git checkout 8d69518fc3ba3ee5a60d90ed7f61d020d59cde0d
Note: switching to '8d69518fc3ba3ee5a60d90ed7f61d020d59cde0d'.
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 switching back to a branch.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:
git switch -c <new-branch-name>
Or undo this operation with:
git switch -
Turn off this advice by setting config variable advice.detachedHead to false
HEAD is now at 8d69518 add readme
修改从某个提交中检出的内容并再次提交会发现新的提交不指向任何分支(即不对任何分支有影响)
xy@DESKTOP-BG9HNHK MINGW64 ~/Desktop/web/web2 ((8d69518...))
$ vi doc/readme
xy@DESKTOP-BG9HNHK MINGW64 ~/Desktop/web/web2 ((8d69518...))
$ git commit -am "checkout with modify"
warning: LF will be replaced by CRLF in doc/readme.
The file will have its original line endings in your working directory
[detached HEAD 5b94258] checkout with modify
1 file changed, 1 insertion(+), 1 deletion(-)
xy@DESKTOP-BG9HNHK MINGW64 ~/Desktop/web/web2 ((5b94258...))
$ git log
commit 5b9425889d42f8b6f690abd0f4bbfd6bf488a16e (HEAD)
Author: 雪饮 <1509272975@qq.com>
Date: Sat Jul 11 14:32:40 2020 +0800
checkout with modify
commit 8d69518fc3ba3ee5a60d90ed7f61d020d59cde0d (master)
Author: 雪饮 <1509272975@qq.com>
Date: Sat Jul 11 10:28:00 2020 +0800
add readme
有紧急任务需要修复线上bug
这里假定上面那个分离头指针并修改了部分内容的提交是可以修复线上一个bug的,所以先切换到master中将该分离头指针后修改提交的这部分创建为一个分支。
在上面任务执行之前我们先看看gitk –all目前能够看到的结果
xy@DESKTOP-BG9HNHK MINGW64 ~/Desktop/web/web2 ((5b94258...))
$ git branch fix_css 5b9425889d42f8b6f690abd0f4bbfd6bf488a16e
于是乎,我们再来看看,一个fix_Css的分支就出来了
关键字词:git,分离,头,指针,分支,上线,bug,checkout