三、Git入门与基本使用(3)(git,基本使用,用,开发技术)

时间:2024-05-07 09:01:54 作者 : 石家庄SEO 分类 : 开发技术
  • TAG :

11、分离头指针情况下的注意事项
 所谓分离头指针,即在git切换到某一commit时,没有绑定在分支或者tag上,此时如果在该commit下进行了文件修改,并且提交commit时,git在日后清理该提交而不保存,因此在进行commit查看时,最好绑定在某一branch或者tag上操作,当然这种操作的好处也存在,即不会破坏原有的branch环境。

$ git checkout 0bd98cb5d0d969cfc35d #直接切换到commit上Note: checking out '0bd98cb5d0d969cfc35d'.You are in 'detached HEAD' state. You can look around, make experimentalchanges and commit them, and you can discard any commits you make in thisstate without impacting any branches by performing another checkout.If you want to create a new branch to retain commits you create, you maydo so (now or later) by using -b with the checkout command again. Example: git checkout -b <new-branch-name>HEAD is now at 0bd98cb Add second file$ git status #此时状态,分离头指针状态HEAD detached at 0bd98cbnothing to commit, working tree clean$ echo "Update second file " >> second.txt #在分离头指针状态下,修改文件并提交$ git commit -am"Update second file"[detached HEAD 71faae4] Update second file 1 file changed, 1 insertion(+) $ git checkout masterWarning: you are leaving 1 commit behind, not connected toany of your branches: 71faae4 Update second fileIf you want to keep it by creating a new branch, this may be a good timeto do so with: git branch <new-branch-name> 71faae4Switched to branch 'master'$ gitk #查看在分离头指针下的提交,可以发现git没有保存

三、Git入门与基本使用(3)

$ git branch newsecond 71faae4 #将修改的commit绑定到一个新的分支$ gitk #查看此时提交,可以发现git已经保存刚才的commit

三、Git入门与基本使用(3)

12、进一步理解HEAD和branch
 HEAD无论是在某一分支或者tag其,最终都会是在某一commit上。同时使用HEAD可以指代当前的commit。

$ cat .git/refs/heads/temp7376bc5b2ebc3e13d4c4552ebdef348a17cd4eef$ git cat-file -t 7376bc5b2commit

13、怎么删除不需要的分支

$ git branch master newsecond* temp$ git branch -d newseconderror: The branch 'newsecond' is not fully merged.If you are sure you want to delete it, run 'git branch -D newsecond'.$ git branch -D newsecondDeleted branch newsecond (was 71faae4).$ git branch master* temp

14、怎么修改最新commit的message

$ git log -n1 #修改前commit 7376bc5b2ebc3e13d4c4552ebdef348a17cd4eef (HEAD -> temp)Author: Jone <764651475@qq.com>Date: Thu Mar 14 17:03:07 2019 +0800 Update fourth file$ git commit --amend #使用该命令进入vim编辑界面直接修改即可[temp 097d397] Update fourth file.txt Date: Thu Mar 14 17:03:07 2019 +0800 1 file changed, 1 insertion(+)$ git log -n1 #修改后commit 097d397f672da771da95cf9baf49057047846617 (HEAD -> temp)Author: Jone <764651475@qq.com>Date: Thu Mar 14 17:03:07 2019 +0800 Update fourth file.txt

15、怎么修改老旧commit的message

$ git log -n3 #要修改导入第二个commit的messagecommit 097d397f672da771da95cf9baf49057047846617 (HEAD -> temp)Author: Jone <764651475@qq.com>Date: Thu Mar 14 17:03:07 2019 +0800 Update fourth file.txtcommit 1d63ec82259b237f58e7525ccf856a03fb880fcdAuthor: Jone <764651475@qq.com>Date: Thu Mar 14 17:01:46 2019 +0800 Add fouth filecommit b843c287804d2b5886167740f9e6c0d327540ee1 (tag: 03tag)Author: Jone <764651475@qq.com>Date: Thu Mar 14 17:00:21 2019 +0800 Add third file$ git rebase -i b843c287804d2b588616 #选择倒数第二个commit的 base信息,即导入第三个commit[detached HEAD bfd373a] Add fouth file.txt Date: Thu Mar 14 17:01:46 2019 +0800 1 file changed, 1 insertion(+) create mode 100644 fourth.txtSuccessfully rebased and updated refs/heads/temp.

第一张图为需要修改的信息,将pick改为r即可
三、Git入门与基本使用(3)
第二张图为修改后的commit 信息
三、Git入门与基本使用(3)

$ git log -n3 #查看修改后的messagecommit ce587039661c88fd508035fd103a012e33c057ac (HEAD -> temp)Author: Jone <764651475@qq.com>Date: Thu Mar 14 17:03:07 2019 +0800 Update fourth file.txtcommit bfd373ab1dd5b2d578bac9cacd4d89d0066c51afAuthor: Jone <764651475@qq.com>Date: Thu Mar 14 17:01:46 2019 +0800 Add fouth file.txtcommit b843c287804d2b5886167740f9e6c0d327540ee1 (tag: 03tag)Author: Jone <764651475@qq.com>Date: Thu Mar 14 17:00:21 2019 +0800 Add third file
 </div> <div class="zixun-tj-product adv-bottom"></div> </div> </div> <div class="prve-next-news">
本文:三、Git入门与基本使用(3)的详细内容,希望对您有所帮助,信息来源于网络。
上一篇:动态正17边光阑Canvas代码,借此向十九世纪伟大数学家高斯致敬下一篇:

10 人围观 / 0 条评论 ↓快速评论↓

(必须)

(必须,保密)

阿狸1 阿狸2 阿狸3 阿狸4 阿狸5 阿狸6 阿狸7 阿狸8 阿狸9 阿狸10 阿狸11 阿狸12 阿狸13 阿狸14 阿狸15 阿狸16 阿狸17 阿狸18