idea和Webstorm上使用git和github,碼雲

因爲以前一直使用svn,如今項目使用git,顧根據網上找的學習資料,本身梳理了下,收穫蠻多,這裏作個記錄,若是能幫助到您那是最好不過的。git

 

1.大體步驟

使用工具:idea,github,碼雲
webstorm和idea因爲都是一個公司的產品,操做手法基本一致,這裏主要是講idea
1.安裝idea,下載git工具,idea中進行關聯
2.在本機上生成公鑰和私鑰,而後在本身的github和碼雲帳號上進行註冊,這樣才能把本身的項目上傳上去。
3.在主分支master上進行git add,commit,push,pull等演示操做
4.模擬開個分支而後再合併主分支的操做
5.使用stash存儲合併主分支
6.模擬一些特殊場景的報錯解決方法
7.github和碼雲上傳的介紹
8.本次學習git,github,碼雲所推薦您看的一些文章

2.git客戶端下載

2.1 安裝完成後,在開始菜單裏找到「Git」->「Git Bash」,蹦出一個相似命令行窗口的東西,就說明Git安裝成功!打開Git Bash 命令行操做界面。github

 

 
image.png

 

2.2建立ssk,得到本機的公鑰和私鑰web

ssh-keygen -t rsa -C "youremail@example.com"
 
image.png

 

若是一切順利的話,能夠在用戶主目錄裏找到.ssh目錄,裏面有id_rsa和id_rsa.pub兩個文件,這兩個就是SSH Key的祕鑰對,id_rsa是私鑰,不能泄露出去,id_rsa.pub是公鑰,能夠放心地告訴任何人,目錄就是上面的c:/users/sunjian/.ssh/id_rsa
第2步:登錄GitHub,打開「Account settings」,「SSH Keys」頁面:
而後,點「Add SSH Key」,填上任意Title,在Key文本框裏粘貼id_rsa.pub文件的內容:spring

 

 
image.png

 

 
image.png

 

 
image.png

 

 
image.png

 

 
image.png

 

3.私鑰公鑰配置好了,如今上傳到github的路已經打通了。
3.1在idea上新建一個springboot項目用來測試github緩存

 

 
image.png

這步做用主要是能夠把本地項目上傳到github上面springboot

 

 
image.png

 

 
image.png

 

如今就先把這個springbootdemo上傳到github上面,而後在測試commit,add,pull,pushbash

 

 
image.png

 

 
image.png

 

 
image.png

 

 
image.png

如何把本地修改的文件先放到本地庫中再從本地庫中去除服務器

 

 
image.png
 
image.png

若是是新增文件夾,必定要把文件夾git add進去,光add文件也不行.app

 

 
image.png

 

 
image.png

 

 
image.png

 

 
image.png

 

 
image.png

 

 
image.png

 

 
image.png

 

push完成,遠程github服務器更新了ssh

 

 
image.png

 

 
image.png


至關於git log這個指令

 
image.png

 

 
image.png


compare with 也是和最近一次線上版本進行比較,compare with branch是和分支上的代碼進行比較.
show current revision 能夠查看這次文件提交的版本號

 
image.png

 

 
image.png

 

 
image.png

 

 
image.png

 

居然可以回退上2個版本,服務器上的沒刪,本地的回退了2個版本。那就要可以返回到最近那個版本。如何操做呢

 

 
image.png


另外因爲回退到上2個版本了,黃色卡片(head)如今指向的是springbootdemo測試git和github,因此這個head就是一個版本的index下標

 
image.png

 

 
image.png

 

這個版本號也不必寫全,git是模糊搜索的,不寫全可能會搜索出多個版本,你在選擇其中一個版本便可

 

 
image.png

 

 
image.png

 

 
image.png

 

 
image.png

 

 
image.png


若是想把遠程master分支上的TestDemo2也刪除掉,先本地刪除後,再commit changes到master分支,就能夠刪掉master分支上的TestDemo2

 
image.png

 

 
image.png

 

 
image.png


commit以後只是放到了暫存區,而後還須要push以後才能更新master分支的版本庫,刪除testdemo2

 
image.png

 

 
image.png

 

 
image.png

 

 
image.png

 

 
image.png

 

 
image.png

 

說明如今是在dev的分支上,咱們如今git add,commit,push,先提交到本身的dev分支上

 

 
image.png

 

 
image.png

 

 
image.png

 

 
image.png

 

 
image.png

 

 
image.png

 

 
image.png

 

 
image.png

 

 
image.png

 

 
image.png

 

 
image.png

 

 
image.png

 

 
image.png

 

 
image.png

 

 
image.png

 

 
image.png

 

 
![image.png](//upload-images.jianshu.io/upload_images/5548226-12710c7cf02bf76a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

 

 
image.png

 

 
image.png

 

 
image.png

 

 
image.png

 

 
image.png

 

 
image.png


status20171227這個至關因而一個臨時存儲的id,須要記錄,而後再右下角new branch,建立分支的時候吧status20171227記錄上去便可
status和new branch普通分支的區別是:好比在master主分支基礎上建立了一個status,那就是吧master主分支存儲起來放到另一個分支上去進行修改,改完之後在恢復到master上面進行合併。
new branch就如前面看到的,只是將master當中其中一部分已經commit的放到另一個分支上去,不是master所有內容
這些操做只要commit便可,不須要push遠程倉庫,commit就是放在緩存區,而後本地合併完之後,再push到遠程分支上。

 
image.png

 

 
image.png

 

 
image.png

 

 
image.png

 

 
image.png

 

 
image.png

 

 
image.png

接下來講下如何使用碼雲

首先要註冊碼雲的帳號密碼,操做手法和github差很少,把公鑰和私鑰去碼雲那邊註冊。

 

 
image.png

 

 
image.png
 
image.png

 

 
image.png

 

 
image.png

 

 
image.png

 

 
image.png

 

 
image.png

 

 
image.png

 

 
image.png

總結:本次git學習推薦網站
使用WebStorm/IDEA上傳本地項目到GitHub
廖雪峯的官方網站
本次學習的過程:一開始先經過本地git,git bash非圖形化界面練了遍,而後再根據軟件來操做,git裏面有不少命令,軟件當中的一些操做也是經常使用指令,若是知足不了需求,能夠本身輸入指令。下面是git一些經常使用指令。

建立文件夾:          mkdir <name>
進入文件夾:          cd <name>
顯示當前目錄:         pwd
把當前目錄變成Git:     git init
顯示隱藏目錄:         ls -ah
查看git倉庫狀態:      git status
把文件添加到git倉庫:    git add <file name>
把文件提交到倉庫:       git commit -m "說明"
查看修改後的不一樣:       git diff
查看提交歷史:         git log --pretty=oneline
回退到上一個版本:       git reset --hard HEAD^
回退到某個版本:        git reset --hard <commit id>
查看命令歷史:         git reflog
工做區和暫存區對比:  git diff
暫存區和分區對比:       git diff -- cached
工做區和分支對比:       git diff -- <file...>
丟棄工做區的修改:       git checkout -- <file...>
撤銷暫存區的修改:       git reset HEAD <file...> + git checkout -- <file...> 或 git reset --hard HEAD
刪除工做區文件:        rm <file...>
從版本庫刪除該文件:  git rm <file...> + git commit -m "說明"
撤銷工做區文件的刪除: git checkout -- <file...>
撤銷暫存區文件的刪除: git reset HEAD <file...> + git checkout -- <file...> 或 git reset --hard HEAD
建立SSH Key:          ssh-keygen -t rsa -C "15521232672@163.com"
關聯一個遠程庫:        git remote add origin git@github.com:RaymondHww/learngit.git
推送master分支的內容:  git push -u origin master (第一次推送要參數 -u ,以後就不用了)
從遠程克隆倉庫到本地: git clone git@github.com:RaymondHww/gitskills.git
查看分支:               git branch
建立分支:               git branch <name>
切換分支:               git checkout <name>
建立+切換分支:            git checkout -b <name>
合併某分支到當前分支: git merge <name>
刪除分支:               git branch -d <name>
查看分支合併狀況:       git log --graph --pretty=oneline --abbrev-commit
使用普通模式合併:       git merge --no-ff -m "說明" dev
把工做現場儲藏:        git stash
查看儲藏的工做現場:  git stash list
恢復儲藏的工做現場:  git stash apply stash@{0}
刪除stash內容:          git stash drop stash@{0}
恢復並刪除stash內容:   git stash pop
強行刪除未合併的分支: git branch -D <branch_name>
顯示詳細的遠程庫信息: git remote -v
推送分支到遠程庫:       git push origin master 或 git push origin dev
克隆遠程庫到本地後只有master分支
在本地建立和遠程分支對應的分支:git checkout -b branch-name origin/branch-name
創建本地分支和遠程分支的關聯: git branch --set-upstream branch-name origin/branch-name
所以,多人協做的工做模式一般是這樣:
首先,能夠試圖用git push origin branch-name推送本身的修改;
若是推送失敗,則由於遠程分支比你的本地更新,須要先用git pull試圖合併;
若是合併有衝突,則解決衝突,並在本地提交;
沒有衝突或者解決掉衝突後,再用git push origin branch-name推送就能成功!
若是git pull提示「no tracking information」,則說明本地分支和遠程分支的連接關係沒有建立,
用命令git branch --set-upstream branch-name origin/branch-name。
tag就是一個讓人容易記住的有意義的名字,它跟某個commit綁在一塊兒。
打一個新標籤到最新的提交上:      git tag v1.0
打一個新標籤到歷史的提交上:      git tag v1.1 <commit-id>
查看全部標籤:                     git tag
查看標籤信息:                     git show v1.0
建立帶有說明的標籤:              git tag -a v1.2 -m "說明" <commit-id>
經過-s用私鑰簽名一個標籤:          git tag -s v1.3 -m "說明" <commit-id>
刪除本地標籤:                     git tag -d v1.0
推送某個標籤到遠程:              git push origin <tag-name>
一次性推送所有還沒有推送到遠程的標籤:git push origin --tags
刪除已經推送到遠程的標籤:           git tag -d v1.0 而後 git push origin :refs/tags/v1.0

原文連接:https://www.jianshu.com/p/89899575e268


關注個人公衆號,都是滿滿的乾貨!
相關文章
相關標籤/搜索