Git系统学习记录
1,创建分支:
git checkout -b new_branch; //创建分支并切换
git branch new_branch; //创建分支
git checkout new_branch; //切换分支
git branch //查看所有分支并指出当前分支
git merge branch_name //将新分支合并到当前分支
git branch -d branch_name //删除新分支
2,远程分支:
git branch -all[a] //查看远程分支(本地提交版)
git remote show origin //查看远程分支(其他更新后)
git push origin --delete BranchName //删除远程分支
3,合并分支
Fast forward合并分支
git merge BranchName
git log --graph --pretty=oneline --abbrev-commit //查看分支合并情况
git log --graph //查看分支合并图
--no-ff模式合并
git merge --no-ff -m "commit note";
注意:
合并分支时,如果可能,Git会用Fast forward模式,但这种模式下,删除分支后,会
丢掉分支信息。如果要强制禁用Fast forward模式,Git就会在merge时生成一个
新的commit,这样,从分支历史上就可以看出分支信息。
stash //暂存工作,保持工作区的清洁
git stash //暂存该分支的工作内容,注意不是存到暂存区
git stash list //查该工作区的stash
git stash apply //恢复当前的stash,但是不会删除当前stash
git stash pop //恢复当前stash的同时会删除当前stash
强制删除没有合并的分支
git branch -D "deleteing branch not merge"
远程其他分支
git checkout -b branch-name origin/branch-name 本地创建远程分支对应的分支
git branch --set-upstream branch-name origin/branch-name 建立本地分支和远程分支的关联