一、删除不需要的分支
1,现在my-pro项目下,新建若干用于测试的分支。
git checkout master #将HEAD指向master分支
git branch testdel #在master分之下新建分支
git checkout testdel #将HEAD指向testdel分支
#在这里修改一下style.css,例如加一个背景色background:#d8d8d8
git commit css/style.css -m'just a test commit' #在testdel分之下执行一个commit操作
git branch testagain
git checkout master
git branch anothertest
gitk --all #使用gitk可视化查看当前分支状况
经过多次分支新建及commit操作之后,我们的分支变成了如下图的结构:
2,使用git branch -d 【分支名称】命令,删除某个指定分支。
Yooye-2:my-pro yooye$ git branch -av #查看当前分支状态
anothertest dc7ecf7 let index.html link the style file
change-border-color 413552e change the box border-color
* master dc7ecf7 let index.html link the style file
testagain e1e471a just a test
testdel e1e471a just a test
Yooye-2:my-pro yooye$ git checkout master #进入master分支
Switched to branch 'master'
Yooye-2:my-pro yooye$ git branch -d testagain #使用-d删除某个分支
error: The branch 'testagain' is not fully merged.
If you are sure you want to delete it, run 'git branch -D testagain'. #提示我们使用-D进行删除
Yooye-2:my-pro yooye$ git branch -D testagain #使用-D再次尝试删除某个分支
Deleted branch testagain (was e1e471a). #删除成功
Yooye-2:my-pro yooye$ gitk --all #查看删除后的可视化分支状态
删除testagain分之后的状态如下:
3,当我们使用git checkout在testdel与master分支间切换的时候,项目中的style.css等代码文件,会随之切换。如果删除testdel分支,则在该分支下提交的所有commit操作记录将全被移除。所以我们在删除分支的之前一定要做版本确认。
二、修改最近一次commit的描述内容
使用 git commit --amend命令,修改最近一次提交的commit的描述性文字。操作流程如下:
Yooye-2:my-pro yooye$ git checkout testdel #【1】进入testde