提交一個版本git
git add *github
git add -A (添加全部文件到暫存區)spring
git add . (添加新文件和修改文件到暫存區,不包括刪除區)spring-mvc
git add -u (添加修改和刪除文件到暫存區,不包括新建文件)mvc
git commit -m '提交說明'app
git push origin masterssh
查看提交日誌ide
git logfetch
git log --pretty=oneline (顯示一行精簡顯示)ui
git log --pretty=oneline --abbrev-commit (顯示提交短ID)
Git全局變量
git config --global user.name "用戶名" -- 設置用戶名
git config --global user.email "email地址" -- 設置email地址
git config -- list -- 查看本地的global信息
建立Git倉庫
mkdir spring-mvc-study
cd spring-mvc-study
git init
touch README.md
git add README.md
git commit -m "first commit"
git remote add origin https://git.oschina.net/jk_hoap/spring-mvc-study.git
git push -u origin master
已有項目添加遠程庫
cd existing_git_repo
git remote add origin https://git.oschina.net/jk_hoap/spring-mvc-study.git
git push -u origin master
刪除添加的遠程倉庫
git remote rm origin
解決Git的crlf轉換問題
warning: LF will be replaced by CRLF in WebRoot/js/PIE.htc.
The file will have its original line endings in your working directory.
git config --gobal core.autocrlf false
合併分支
git checkout master -- 切換到主分支master
git merge dev -- 合併分支 dev 到 master
查看提交日誌
git log
git log --pretty=oneline (顯示一行精簡顯示)
git log --pretty=oneline --abbrev-commit (顯示提交短ID)
git log --graph (查看合併分支圖)
git reflog
未顯示完退出輸入:q
查看狀態
git status
版本回退
git reset --hard HEAD^ (回退上一個版本)
git reset --hard HEAD~100 (回退前100個版本)
查看版本分支
git branch
建立分支\刪除分支
git branch dev (建立分支dev)
git checkout dev (切換到分支dev)
git branch -d dev (刪除分支)
合併分支
a. git checkout master b. git merge dev (a、b步操做合併dev分支到master分支)
(Fast-forward信息,Git告訴咱們,此次合併是「快進模式」,也就是直接把master指向dev的當前提交,因此合併速度很是快。)
a. git checkout master b. git merge --no-ff -m '註解' dev (合併dev 到master, --no-ff禁用「Fask forward」)
(一般合併分支時,git通常使用」Fast forward」模式,在這種模式下,刪除分支後,會丟掉分支信息,如今咱們來使用帶參數 –no-ff來禁用」Fast forward」模式。)
git checkout -b dev origin/dev (建立遠程origin的dev分支)
將當前工做現場隱藏
git stash (將當前工做現場隱藏)
恢復工做現場
git stash list (查看隱藏的工做現場)
恢復工做現場:
git stash apply恢復,恢復後,stash內容並不刪除,你須要使用命令git stash drop來刪除.另外一種方式是使用git stash pop,恢復的同時把stash內容也刪除了.
查看遠程庫信息
git remote 要查看遠程庫的信息
git remote -v 要查看遠程庫的詳細信息
推送本地庫分支到遠程倉庫
git push origin master
若是報:Non-fast-forward 能夠使用git push -f 強退
也能夠git pull 下載遠程GIT倉庫合併後再提交(git fetch git merge)
git push origin :dev (刪除遠程分支)
git push origin 本地分支名:遠程分支名(推送分支到服務端)
建立標籤
git tag v1.0 (建立標籤v1.0)
git tag -a v0.01 -m 'version 0.01 released' (建立標間帶說明)
git tag (查看有哪些便籤)
git tag -d v1.0 (刪除本地標籤)
git checkout v1.0 (切換到便籤)
git push origin :refs/tags/v1.0 (刪除遠程便籤)
提交常見文件
warning: Your console font probably doesn't support Unicode. If you experience strange characters in the output, consider switching to a TrueType font such as Lucida Console! 解決辦法: $ git config --global core.autocrlf true
克隆一個遠程已有項目到本地
git clone git@git.oschina.net:artemis17/xx.git
-------------------------Git Linux 安裝---------------------------------------------------------------------------
Git下載
http://git-scm.com/download -- 下載地址
使用yum安裝
yum -y install git -- 安裝Git
生成密鑰
ssh-keygen -t rsa -C "***@qq.com" -- 生成密鑰,郵箱換成本身,按三個回車,設置密碼爲空,生成的密鑰放在~/.ssh/ 下(id_rsa是私鑰,id_rsa.pub是公鑰),打開公鑰~/.ssh/id_rsa.pub,拷貝到github或oschina;
Git 配置文件
git config --global color.ui true -- 設置Git命令高亮顯示