分支的操作
查看当前分支——git branch -v
ws199@DESKTOP-2N1I9JA MINGW64 /d/GIT/Git-Space/git.demo (master) $ git branch -v * master 534cbd3 third commit
创建分支——git branch 分支名
ws199@DESKTOP-2N1I9JA MINGW64 /d/GIT/Git-Space/git.demo (master) $ git branch hot-fix ws199@DESKTOP-2N1I9JA MINGW64 /d/GIT/Git-Space/git.demo (master) $ git branch -v hot-fix 534cbd3 third commit * master 534cbd3 third commit
切换分支——git checkout 分支名
ws199@DESKTOP-2N1I9JA MINGW64 /d/GIT/Git-Space/git.demo (master) $ git checkout hot-fix Switched to branch 'hot-fix' ws199@DESKTOP-2N1I9JA MINGW64 /d/GIT/Git-Space/git.demo (hot-fix) $ ws199@DESKTOP-2N1I9JA MINGW64 /d/GIT/Git-Space/git.demo (hot-fix) $ git branch -v * hot-fix 534cbd3 third commit master 534cbd3 third commit
合并分支——git merge 分支名
ws199@DESKTOP-2N1I9JA MINGW64 /d/GIT/Git-Space/git.demo (master) $ git merge hot-fix Updating 534cbd3..017517e Fast-forward hello.txt | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-)
合并分支(冲突合并)
检测有文件有两处修改
显示冲突
ws199@DESKTOP-2N1I9JA MINGW64 /d/GIT/Git-Space/git.demo (master) $ git merge hot-fix Auto-merging hello.txt CONFLICT (content): Merge conflict in hello.txt Automatic merge failed; fix conflicts and then commit the result. ws199@DESKTOP-2N1I9JA MINGW64 /d/GIT/Git-Space/git.demo (master|MERGING) $ ws199@DESKTOP-2N1I9JA MINGW64 /d/GIT/Git-Space/git.demo (master|MERGING) $ git status On branch master You have unmerged paths. (fix conflicts and run "git commit") (use "git merge --abort" to abort the merge) Unmerged paths: (use "git add <file>..." to mark resolution) both modified: hello.txt no changes added to commit (use "git add" and/or "git commit -a")
冲突合并
# 1.查看冲突代码 ws199@DESKTOP-2N1I9JA MINGW64 /d/GIT/Git-Space/git.demo (master|MERGING) $ vim hello.txt # <<<< HEAD 当前分支代码 # <<<< HEAD 当前分支代码 ======= # ======= 合并分支代码 >>>>>>> hot-fix #删除特殊符号 以及 重复代码 #2.添加到暂存区 ws199@DESKTOP-2N1I9JA MINGW64 /d/GIT/Git-Space/git.demo (master|MERGING) $ git add hello.txt #3.提交本地库(不能带文件名) ws199@DESKTOP-2N1I9JA MINGW64 /d/GIT/Git-Space/git.demo (master|MERGING) $ git commit -m "marge test" fatal: cannot do a partial commit during a merge. #4.切换分支查看 ws199@DESKTOP-2N1I9JA MINGW64 /d/GIT/Git-Space/git.demo (master) $ git checkout hot-fix Switched to branch 'hot-fix' #冲突合并,合并当前分支,不合并被合并分支 # head ---> master(分支内容)--->版本号 # HEAD决定当前分支