Git检出,建立子版本库更新并且合并到master
程序员文章站
2022-07-03 09:54:50
Git检出,建立子版本库更新并且合并到master
HEAD:
head可以理解为“头指针”,是当前工作区的“基础版本”,当执行...
Git检出,建立子版本库更新并且合并到master
HEAD:
head可以理解为“头指针”,是当前工作区的“基础版本”,当执行提交时,HEAD指向的提交将作为新提交的父提交。看看当前HEAD指向。
$ cat .git/HEAD ref: refs/heads/master
查看master 和 head
$ git rev-parse HEAD master 4b9bdcab95d15dd79e7d41c506c9e6e8b1f7c56e 4b9bdcab95d15dd79e7d41c506c9e6e8b1f7c56e
此时创建新分支
git checkout -b “myNewBranch”
$ git checkout -b "myNewBranch" Switched to a new branch 'myNewBranch' # rock @ localhost in ~/IdeaProjects/webDemoTwo on git:myNewBranch o [20:34:49]
会发现当前在分支 myNewBranch 上
$ cat .git/HEAD ref: refs/heads/myNewBranch
此时修改文件并提交
# rock @ localhost in ~/IdeaProjects/webDemoTwo on git:myNewBranch o [20:34:49] $ git add . # rock @ localhost in ~/IdeaProjects/webDemoTwo on git:myNewBranch x [20:36:39] $ git ci -m "new barnch" [myNewBranch 870ee16] new barnch 1 file changed, 3 insertions(+)
此时查看git 和 master 在哪个提交上
$ git rev-parse HEAD master 870ee16a02d07cfddb59d5906cafa48947aafe70 4b9bdcab95d15dd79e7d41c506c9e6e8b1f7c56e
当前head 在870ee16a02d07cfddb59d5906cafa48947aafe70上;注意将head切换到master上查看log
执行切换:
$ git checkout master Switched to branch 'master' Your branch is ahead of 'origin/master' by 4 commits. (use "git push" to publish your local commits)
查看log
commit 4b9bdcab95d15dd79e7d41c506c9e6e8b1f7c56e Author: wangchengwei Date: Tue Nov 28 20:20:48 2017 +0800 测试head和master不在一起的提交 commit 049723fa6f1ba44da79d2afd4727356b29bbaa3a Author: wangchengwei Date: Tue Nov 28 20:17:02 2017 +0800 test3 commit ec4dc0fd08a71f57177b298c8347a97ff646f1a7 Author: wangchengwei Date: Mon Nov 27 08:10:06 2017 +0800 重置test2 commit 0bfd67bac8a3640bcc70041d7540644a1240cf3d Author: wangchengwei Date: Mon Nov 27 08:09:20 2017 +0800 重置test1
并未发现 870ee16a02d07cfddb59d5906cafa48947aafe70的提交。
查看版本库中此id 的log发现在版本库是有这个id的信息
git show 870ee16a02d07cfddb59d5906cafa48947aafe70 commit 870ee16a02d07cfddb59d5906cafa48947aafe70 Author: wangchengwei Date: Tue Nov 28 20:36:48 2017 +0800 new barnch diff --git a/firstweb/src/git/git7/TestTwo.java b/firstweb/src/git/git7/TestTwo.java index fee886f..deea8b3 100644 --- a/firstweb/src/git/git7/TestTwo.java +++ b/firstweb/src/git/git7/TestTwo.java @@ -10,6 +10,9 @@ public class TestTwo { System.out.printf("重置test4 测试head头"); + System.out.printf("im in new branch"); + +
而当前head和master在同一id下。此时需要执行merge将这一分支的信息合并到master下。
$ git merge 870ee16a02d07cfddb59d5906cafa48947aafe70 Updating 4b9bdca..870ee16 Fast-forward firstweb/src/git/git7/TestTwo.java | 3 +++ 1 file changed, 3 insertions(+)
再次查看 head 和master
$ git rev-parse head master 870ee16a02d07cfddb59d5906cafa48947aafe70 870ee16a02d07cfddb59d5906cafa48947aafe70
此时head和master都指向了这一个提交
上一篇: mysql游标使用实例讲解
下一篇: 基于代理的Web扫描器的实现