首先创建并且切换分支到dev:
$ git checkout -b dev
Switched to a new branch 'dev'
查看当前分支状态:
$ git branch
* dev
master
当前文件内容:
<pre name="code" class="plain">$ cat readme.txt
Hello World!
this is a git file.
this file will commit to git.
we are young!yes we are young!
我们修改文件内容:
$ cat readme.txt
Hello World!
this is a git file.
this file will commit to git.
we are young!yes we are young!
Creating a new branch is quick.
然后添加并提交:
$ git add readme.txt
$ git commit -m "branch dev modify"
[dev ecf03eb] branch dev modify
1 file changed, 1 insertion(+)
然后切换回master主分支:
$ git checkout master
Switched to branch 'master'
Your branch is ahead of 'origin/master' by 4 commits.
(use "git push" to publish your local commits)
这时候我们的文件的内容:
$ cat readme.txt
Hello World!
this is a git file.
this file will commit to git.
we are young!yes we are young!
dev修改的内容并没有体现在master分支上去。合并分支dev到master分支上去:
$ git merge dev
Updating dc7f36c..ecf03eb
Fast-forward
readme.txt | 1 +
1 file changed, 1 insertion(+)
在查看文件内容:
$ cat readme.txt
Hello World!
this is a git file.
this file will commit to git.
we are young!yes we are young!
Creating a new branch is quick.
修改成功。由两个图可以很清晰的看到这个过程(git gui):
最后可以删除分支:
$ git branch -d dev
Deleted branch dev (was ecf03eb).
ZhangLei@ZHANGLEI-PC /d/GitRepository/myapp1 (master)
$ git branch
* master