對於項目協同開發,git是很不錯的使用,對於一般的開發一般分爲以下幾個步驟:
1,創建本地倉庫mkdir your dir
2,實例化本地倉庫 git init (ls時會有-------git的文件)
3,檢出項目(你入職的時候項目已經開始了,你需要將項目down下來) git clone path(repository)
4,開始自己模塊開發,將寫出的代碼提交緩存區 git add yourprogram
5,將緩存區的代碼提交到隱藏分支 git commit -m “your program detail”
6,真正提交自己測試後較爲完善代碼到主分支了(項目管理服務器) git push origin master 其中origin是遠程代碼庫的別名
當出現版本錯誤提交,新版本運行不穩定等情況,需要返回到上一個版本:
1,使用git reset --hard commit_id(注:先使用git log 查看提交的版本ID,信息太多可以使用git log --pretty=oneline;或者使用git reset --hard HEAD^。注:head^表示上一個版本,HEAD^^表示上上個版本,以此類推)
2,當然想返回到未來先使用git reflog查看命令過程,然後在返回指定的未來版本
其他操作:
1,idea可以進行比較本地版本和遠端版本的不同,但是通過使用git diff HEAD origin/branchname(想查看運端分支的最新情況使用git branch -r或者git branch -a注:-a會顯示本地的版本情況) 可以對比出差異;也可以使用首先輸入:git fetch origin 然後輸入:git diff localbranch origin/branchname;注:git pull獲得最新版本併合並,git fetch獲得最新版本不自動合併。
2,創建分支和合並分支:
- git checkout -b branchname
- git branch(查看當前分支的狀態)
- git checkout master(當對分支開發和測試完成後)
- git merge branchname(和並分支;命令用於合併指定分支到當前分支)
3,分支創建的兩種方式:
- 本地創建分支然後再推送到遠端----git checkout -b branchname ----git push origin branchname(本地):branchname(遠端,如果遠端不存在會自動創建)----git branch --set-upstream-to= origin/branchname(本地與遠端建立連接) localbranch
- git checkout -b branchname origin/branchname(遠端已存在分支時)
4,刪除本地分支和遠端分支:
- 本地分支的刪除----git branch -d branchname
- 遠端分支的刪除----git push origin --delete branchname
5, 分支修改:
- git branch -m localbranch(本地分支) newbranch(重命名分支)
6,解除本地分支和遠端分支的關聯
- git remote remove origin
7,本地分支關聯遠程分支
- git pull origin branchname
8,拉取遠端所有分支
- git fetch --all
其他詳細參考:http://www.bootcss.com/p/git-guide/