Jenkins持续集成 之 git分支

Jenkins持续集成 之 git分支

什么是分支

软件项目中启动一套单独的开发线的方法

为什么使用git

1.可以很好的避免版本兼容开发的问题,避免不同版本之间的相互影响。
2.封装一个开发阶段。
3.解决bug的时候新建分支,用于对该bug的研究。

git中跟分支相关的命令

git branch 分支名---创建一个新的分支
git branch ---不加任何参数,列出所有的分支,分支前面有*号,代表该分支为当前所在分支
* 创建分支的时候,分支名不能使用特殊符号
git branch -d 分支名---删除分支
git branch -m 旧分支名 新分支名---分支名改名
git checkout 分支名---切换分支,如果在分支上面对文件进行修改之后,没有commit就切换到另外一个支支
这个时候会报错,因为没有commit的文件在切换分支之后会不覆盖
git checkout -f 分支名---强制切换分支。

git 分支展示

kangdeMacBook-Air:cedarhd kang$ git branch    #查看当所所有分支
* master
kangdeMacBook-Air:cedarhd kang$ git branch v1.0   #新建一个v1.0的分支
kangdeMacBook-Air:cedarhd kang$ git branch
* master
    v1.0
kangdeMacBook-Air:cedarhd kang$ git checkout v1.0   #切换到v1.0的分支
Switched to branch 'v1.0'
kangdeMacBook-Air:cedarhd kang$ git branch
    master
* v1.0
kangdeMacBook-Air:cedarhd kang$ touch test9.txt    #在v1.0的分支上创建test9.txt
kangdeMacBook-Air:cedarhd kang$ ls -al
total 32
drwxr-xr-x  13 kang  staff  442 12  2 00:12 .
drwxr-xr-x   5 kang  staff  170 12  1 16:48 ..
drwxr-xr-x  16 kang  staff  544 12  2 00:12 .git
-rw-r--r--   1 kang  staff    3 12  1 16:18 test.txt
-rw-r--r--   1 kang  staff   23 12  1 16:18 test1.txt
-rw-r--r--   1 kang  staff    0 12  1 16:18 test2.txt
-rw-r--r--   1 kang  staff    6 12  1 16:18 test3.txt
-rw-r--r--   1 kang  staff   17 12  1 16:18 test4.txt
-rw-r--r--   1 kang  staff    0 12  1 16:21 test5.txt
-rw-r--r--   1 kang  staff    0 12  1 16:37 test6.txt
-rw-r--r--   1 kang  staff    0 12  1 22:43 test7.txt
-rw-r--r--   1 kang  staff    0 12  1 23:15 test8.txt
-rw-r--r--   1 kang  staff    0 12  2 00:12 test9.txt
kangdeMacBook-Air:cedarhd kang$ git add test9.txt     #提交到暂存区
kangdeMacBook-Air:cedarhd kang$ git commit -m "test9.txt"     #提交到本地仓库
[v1.0 6111bf3] test9.txt
 Committer: kang <[email protected]>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly. Run the
following command and follow the instructions in your editor to edit
your configuration file:

        git config --global --edit

After doing this, you may fix the identity used for this commit with:

        git commit --amend --reset-author

 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 test9.txt
kangdeMacBook-Air:cedarhd kang$ ls -al
total 32
drwxr-xr-x  13 kang  staff  442 12  2 00:12 .
drwxr-xr-x   5 kang  staff  170 12  1 16:48 ..
drwxr-xr-x  16 kang  staff  544 12  2 00:12 .git
-rw-r--r--   1 kang  staff    3 12  1 16:18 test.txt
-rw-r--r--   1 kang  staff   23 12  1 16:18 test1.txt
-rw-r--r--   1 kang  staff    0 12  1 16:18 test2.txt
-rw-r--r--   1 kang  staff    6 12  1 16:18 test3.txt
-rw-r--r--   1 kang  staff   17 12  1 16:18 test4.txt
-rw-r--r--   1 kang  staff    0 12  1 16:21 test5.txt
-rw-r--r--   1 kang  staff    0 12  1 16:37 test6.txt
-rw-r--r--   1 kang  staff    0 12  1 22:43 test7.txt
-rw-r--r--   1 kang  staff    0 12  1 23:15 test8.txt
-rw-r--r--   1 kang  staff    0 12  2 00:12 test9.txt
kangdeMacBook-Air:cedarhd kang$ git branch
* master
    v1.0
kangdeMacBook-Air:cedarhd kang$ git checkout master  #切换到master分支
Switched to branch 'master'
Your branch is ahead of 'origin/master' by 1 commit.
    (use "git push" to publish your local commits)
    kangdeMacBook-Air:cedarhd kang$ ls -al     #此时v1.0的test9.txt不见了
    total 32
    drwxr-xr-x  12 kang  staff  408 12  2 00:12 .
    drwxr-xr-x   5 kang  staff  170 12  1 16:48 ..
    drwxr-xr-x  16 kang  staff  544 12  2 00:12 .git
    -rw-r--r--   1 kang  staff    3 12  1 16:18 test.txt
    -rw-r--r--   1 kang  staff   23 12  1 16:18 test1.txt
    -rw-r--r--   1 kang  staff    0 12  1 16:18 test2.txt
    -rw-r--r--   1 kang  staff    6 12  1 16:18 test3.txt
    -rw-r--r--   1 kang  staff   17 12  1 16:18 test4.txt
    -rw-r--r--   1 kang  staff    0 12  1 16:21 test5.txt
    -rw-r--r--   1 kang  staff    0 12  1 16:37 test6.txt
    -rw-r--r--   1 kang  staff    0 12  1 22:43 test7.txt
    -rw-r--r--   1 kang  staff    0 12  1 23:15 test8.txt
    kangdeMacBook-Air:cedarhd kang$ git checkout v1.0    #切换到v1.0分支
    Switched to branch 'v1.0'
    kangdeMacBook-Air:cedarhd kang$ ls    #test9.txt存在
    test.txt    test2.txt   test4.txt   test6.txt   test8.txt
    test1.txt   test3.txt   test5.txt   test7.txt   test9.txt

猜你喜欢

转载自blog.51cto.com/12965094/2324834