1. 程式人生 > >Jenkins持續集成 之 git分支

Jenkins持續集成 之 git分支

項目 git chan mod 進行 his 符號 刪除 fix

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

Jenkins持續集成 之 git分支