github的使用---git版本控制

git 安裝linux

ubuntu下: sudo apt-get install git 源碼安裝

  

windows下載git軟件便可git

git核心原理github

git經常使用命令shell

 

git add 添加提交任務到暫存區 git commit -m "commit info" 添加提交任務到版本庫 git log 查看提交記錄 git diff 查看工做區和暫存區的差別 git diff --cached 查看暫存區和版本庫的差別 git diff HEAD 查看工做區和版本庫的差別 git status -s 簡短輸出,第一個M表示暫存區和版本庫內容不一致;第二個M表示工做區和暫存區內容不一致 git checkout -- file.txt 把暫存區的file.txt文件恢復到工做區,覆蓋工做區以前的修改。checkout命令主要是把歷史某個版本檢出到工做 區。慎用 git reset HEAD 暫存區的目錄樹被版本庫裏的內容重置,可是工做區不受影響。放棄以前git add的提交。 git reset --hard SHA1號/HEAD 工做區和暫存區的目錄樹被版本庫裏的內容重置。放棄以前git add和個git commit的提交。 git rm file.txt 刪除文件 git blame file.txt 查看文件提交歷史信息,方便定位bug git show-ref 查看所包含的引用 git merge 進行合併操做 git push -u origin master 向遠程版本庫origin的master分支提交 git pull 把遠程版本庫的master分支拉到本地,數據同步服務器端 git tag -m "my first tag" mytagv1.0 製做里程碑 git cat-file tag mytagv1.0 查看mytagv1.0提交信息 git tag -l -n1 查看全部tag,n1顯示一行信息 git tag -d mytagv1.0 刪除tag git branch newbranch 建立分支 git checkout newbranch 切換到newbranch分支 git branch -d newbranch 刪除分支,如沒合併,則失敗 git branch -D newbranch 強制刪除分支 git push origin :newbranch 先刪除本地分支,再刪除遠程版本庫對應分支 git show-ref 查看本地引用 git checkout -b hello-1 origin/hello-1 建立跟蹤遠程分支的本地分支,隨後能夠pull和push遠程分支 git remote add new-remote file:///path/hello-1.git
建立遠程版本庫 git remote -v 查看遠程版本庫

 

 

 github協做開發GitHub(網址 https://github.com/)是一個面向開源及私有軟件項目的託管平臺,由於只支持Git做爲惟一的版本庫格式進行託管,故名GitHub數據庫

github地址:ubuntu

https://github.com/

 建立賬號vim

 

建立項目
  1.建立項目
  2.下載項目windows

1. 網頁下載zip文件
2. git clone https://github.com/xwpfullstack/itcast.git

  linux終端配置服務器

1 配置環境
設置系統全局用戶ssh

Global setup: git config --global user.name "Your Name" git config --global user.email xwp_fullstack@163.com

每一個項目也能夠單獨在配置文件裏設置用戶

vim .git/config

  查看環境配置

git config -l

  刪除全局配置

git config --unset --global user.name
git config --unset --global user.email

  

ssh配置
1.生成ssh-key,在終端下執行如下命令

itcast$ ssh-keygen ~/.ssh/id_rsa是私鑰文件 ~/.ssh/id_rsa.pub是公鑰文件

 

2.把公鑰上傳到github上

 


配置好ssh公鑰後,在終端下執行如下命令

 

ssh -T git@github.com Hi gotgithub! You've successfully authenticated, but GitHub does not provide shell access. 出
現上述提示證實配置好ssh

 

.ssh-key的做用
用戶命令行下提交代碼時不須要再輸入帳號和密碼,默認https協議是須要輸入的
修改項目中./git/config文件,把url換成 url = git@github.com:註冊名/項目名.git
例如: url = git@github.com:xwpfullstack/test.git

 

第一個項目

1 新建空項目
先在github頁面建立一個項目world

git clone https://github.com/xwpfullstack/world.git
cd world echo "world"" >> README.md
git add README.md

 git commit -m "first commit"
 git remote add origin https://github.com/xwpfullstack/world.git
 git push -u origin maste

把一個已經存在的git管理的項目放到github上託管

git remote add origin https://github.com/xwpfullstack/world.git
git push -u origin master

  

下載項目
三種下載方式:

https協議下載
git clone https://github.com/username/test.git
Git-daemon協議下載
git clone git://github.com/username/test.git
打包下載

 

 分支

 

git branch -a
查看全部分支,含遠程
git branch
查看本地分支
git branch -r
查看遠程分支
git branch newbranch
建立新分支
git branch -d oldbranch
刪除分支oldbranch
git push origin newbranch
把新分支同步到遠程倉庫
git push origin :oldbranch
刪除遠程oldbranch分支
git checkout -b newbranch
切換到另外一分支,若是不存在則建立
git checkout branch
切換到另外一分支
git clone新項目時
不管當前項目在什麼分支,都是下載默認master分支
git checkout master
git merge anthorbranch
git push origin maste
合併開發分支到master分支
git pull儘可能少使用,隱含了合併信息
get featch 下載遠程origin/master更新
git diff master origin/master
查看本地和遠程庫的區別
get merge origin/master
合併遠端更新到本地

  

tag
tag

git tag v1.0 -m "tag v1"
建立一個標籤
git push origin --tags
把全部標籤同步到遠程庫
git checkout v1.0
檢出v1.0版本
git reset --hard v1.0
使代碼重置,回到v1.0。此功能慎用,後開發的代碼會丟失
git tag -d v1.0
刪除標籤v1.0
git push origin :v1.0
刪除遠程庫裏標籤
git tag -l -n1
查看全部tag

  


 HEAD
HEAD

指向當前提交點,遊標指針 HEAD^ 上次提交點,父提交點 git checkout HEAD^ 切換到上次提交點,不在分支 git reset --hard HEAD^ 撤銷本次提交,恢復到上次提交狀態,新建立的文件會丟棄 4.5.7 忽略監控文件 .gitignore通常把.o和臨時文件設置進去,忽略代碼監控,如某項目.gitignore: #過濾數據庫文件、sln解決方案文件、配置文件
*.mdb
*.ldb

*.sln
*.config

#過濾文件夾Debug,Release,obj
Debug/
Release/
obj/

 

而後調用git add. ,執行 git commit便可。問題:.gitignore只適用於還沒有添加到git庫的文件。若是已經添加了,則需用git rm移除後再從新commit。

相關文章
相關標籤/搜索