赞
踩
- ### --- 创建feature1分支并提交版本
- ~~~ 创建feature1分支
-
- [root@server12 shell]# git checkout -b feature1 # 创建新的feature1分支
- ### --- 修改内容,修改readme.txt最后一行,改为:
-
- [root@server12 shell]# vim readme.txt
- Creating a new branch is quick AND simple.
- ### --- 提交分支
-
- [root@server12 shell]# git add readme.txt # 在feature1分支上提交
- [root@server12 shell]# git commit -m "AND simple"
- [feature1 0c34577] AND simple
- 1 file changed, 1 insertion(+)
- create mode 100644 readme.txt
- ### --- 切换到master分支
-
- [root@server12 shell]# git checkout master # 切换到master分支
- Switched to branch 'master'
- ### --- 查看分支记录
- ~~~ Git还会自动提示我们当前master分支比远程的master分支要超前1个提交。
-
- [root@server12 shell]# git branch
- feature1
- * master
- ### --- 在master分支上把readme.txt文件的最后一行改为:
-
- [root@server12 shell]# vim readme.txt
- Creating a new branch is quick & simple.
- ### --- 将修改后的分支内容提交
-
- [root@server12 shell]# git add readme.txt
- [root@server12 shell]# git commit -m "& simple"
- [master b68fcb2] & simple
- 1 file changed, 1 insertion(+)
- create mode 100644 readme.txt
- ### --- 现在,master分支和feature1分支各自都分别有新的提交
- ~~~ 这种情况下,Git无法执行“快速合并”,只能试图把各自的修改合并起来,
- ~~~ 但这种合并就可能会有冲突,我们试试看:
- ~~~ readme.txt文件存在冲突,必须手动解决冲突后再提交。
-
- git merge feature1 Auto-merging readme.txt CONFLICT (content):
- Merge conflict in readme.txt Automatic merge failed;
- fix conflicts and then commit the result.
- ### --- 查看冲突的文件并修改冲突文件
- ~~~ Git用<<<<<<<,=======,>>>>>>>标记出不同分支的内容,我们修改后保存再提交:
- [root@server12 shell]# git status # 可以显示冲突的文件;
- Git is a distributed version control system.
- Git is free software distributed under the GPL.
- Git has a mutable index called stage.
- Git tracks changes of files.
- <<<<<<< HEAD Creating a new branch is quick & simple. ======= Creating a new branch is quick AND simple. >>>>>>> feature1
- ### --- 重新提交
-
- [root@server12 shell]# git add readme.txt
- [root@server12 shell]# git commit -m "conflict fixed"
- [master 59bc1cb] conflict fixed
- ### --- 最后,删除feature1分支:
-
- [root@server12 shell]# git branch -D feature1
- Deleted branch feature1 (was 0c34577).
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。