分支管理
创建分支
git branch (branchname)
例子
git branch test1
切换分支
git checkout (branchname)
例子
git checkout test1
分支查询
git branch
结果中*标记表示当前分支
删除分支
git branch -d (branchname)
例子
git branch -d test1
删除远程分支
$ git push origin --delete (branchname)
合并分支
$ git merge (branchname)
将当前分支合并到branchname分支中
例子
$ git merge test1
假如出现冲突,解决冲突
我们事先对test1分支中一个文件进行操作后推送到服务器,然后切换到master分支进行操作同一个文件内的同一段内容,最后提交服务器最后将master合并到test1中
Auto-merging test.txt
CONFLICT (content): Merge conflict in test.txt
Automatic merge failed; fix conflicts and then commit the result.
这是提醒你出现的冲突。这个时候查看文件提示test出现冲突
$ git status -s
UU test.txt
这个时候你的分支发生了变化
这个时候直接修改冲突的文件test
然后再次提交,然后就成功了
这里本来只有个提交成功的图的,之前使用有道笔记在工作之余写的,结果回到家中图片变没了ε=(´ο`*)))唉
标签管理
一般我们项目更新到一定阶段需要进行版本发布的时候。这个状态下的代码一般我们需要做一个标记方便后续
创建标签
$ git tag -a <tagname>
用此命令创建标签会进入一个文本编辑页面,为标签名称,要求添加标签信息,或者使用这个命令直接进行提交
git tag -a <tagname> -m "标签备注信息"
修改已经推送的标签内容
假如在打了标签后,又发生了变化,而依旧决定使用之前的标签名称可以,施工–tags -f来强制更新标签内容
git tag <tagname> -m "修订过后的版本"
git push origin --tags -f
查询标签
查询标签列表
$ git tag
匹配查询
查询指定规则的标签
$ git tag --list 'v*'
查询v开头的标签列表
查看标签的详细内容
$ git show <tagname>
推送标签
git push origin <tagname>
推送所有的本地标签
$ git push origin --tags
删除标签
删除本地标签
$ git tag -d <tagname>
删除远程标签
删除标签也是使用push但是和推送标签相比多了一些内容
$ git push origin :refs/tags/<tagname>
编辑标签
对历史提交内容追加标签,
首先通过日志获得提交索引
git log --pretty=oneline --abbrev-commit
根据结果对某次提交进行标签补充
git tag <tagname> <commitIndex>
标签名,提交的索引号
切换至指定标签
和切换分支一样,使用checkout命令,不过分支名变成了标签名称
git checkout tag_name
注意此时git处于detached HEAD状态,因为ta并不属于一个分支,而是某一时刻代码的快照,假如你需要对代码进行修改则需要给它分配一个分支
git checkout -b <branch_name> <tag_name>
<branch_name>分支名称, <tag_name>标签名称