官方文档地址
本地代码上传到远程仓库的master
git init //初始化本地代码,新建.git 文件git status // 查看本地文件与服务的差别git add . //讲所有文件添加到本地仓库中git commit -m "添加本次提交记录" // 为本次记录添加说明git remote add origin https://domain.com // 讲本地代码与远程仓库做关联(远程仓库存在的情况下)git pull --rebase origin master // 讲代码定位到origin master 主仓库下git push -u origin master // 推送代码到master分支
本地创建分支并上传到远程服务器
git branch // 查看本地分支git branch -a // display all the branch including remote branchgit checkout -b dev // switch branch to devgit push origin <local branch name>:<remote branch name> // link local branch to remote branch and push to the servegit push origin:<remote branch name> // delete remote branch
删除本地分支
git branch -d 分支名
拉取远程分支到本地
git pull origin/dev // get dev branch to local branch
pull a different branch and switch to the branch
git checkout -b dev origin/dev
合并本地分支到master分支
git checkout master // switch to master branchgit pull origin master // get the newest code in the master branchget merge dev // merge dev code to the local branchgit push origin -d dev // delete dev branch
放弃文件更改
// 1. if you did not use git add command to cache the codegit checkout --filename // discard the filename modifygit checkout . // discard all the modified content in this repository// 2. if you use git add command to cache the codegit reset HEAD filename // discard the filenamegit reset HEAD // discard all the modified file// 3. if you already use git commit command to cache the codegit reset --hard HEAD^ // go back to the last commit statusgit reset --hard commit id // go back to any commit status, commitId is a serial string made by git itself
tags
git push origin --tags // 将tags发送到服务器git tag // inspect all the taggit show v0.0.1 // show the descripiton infogit tag -d v0.0.1 // delete v0.0.1 taggit tag -a v0.0.1 -m 'descript this tag'
progit.pdf
progit_v2.1.34.pdf