GIT常规配置
$ git config -global user.name <name> #设置提交者名字 $ git config -global user.email <email> #设置提交者邮箱 $ git config -global core.editor <editor> #设置默认文本编辑器 $ git config -global merge.tool <tool> #设置解决合并冲突时差异分析工具 $ git config -list #检查已有的配置信息
使用git提交比较大的文件的时候可能会出现这个错误 error: RPC failed; result=22, HTTP code = 411 fatal: The remote end hung up unexpectedly fatal: The remote end hung up unexpectedly Everything up-to-date 这样的话首先改一下git的传输字节限制
git config http.postBuffer 524288000 git config --global http.postBuffer 524288000
$ git init #初始化 $ git add . #添加当前目录所有内容 $ git commit -m "first commit." #提交到本地库,并添加备注
远程操作
$ git remote -v #查看远程版本库信息 $ git remote show <remote> #查看指定远程版本库信息 $ git remote add <remote> <url> #添加远程版本库 $ git fetch <remote> #从远程库获取代码 $ git pull <remote> <branch> #下载代码及快速合并 $ git push <remote> <branch> #上传代码及快速合并 $ git push <remote> : <branch>/<tagname> #删除远程分支或标签 $ git push -tags #上传所有标签
详细说明
克隆项目:
git clone <URL>
克隆分支:
git clone -b branchName <URL>
克隆tag:
1、克隆整个项目(git clone <URL>) 2、git checkout -b branchName tagName(tag是独立的项目,如果要编辑就要将其变为普通的分支)
添加并提交文件或文件夹
git add . | file git commit -m "description" git commit 之后发现有些文件不需要commit则用 git rm --cached 文件名 (删除本地仓库缓存文件,并不影响工作目录)
非git项目想加入git管理如下操作
git init git add . git commit -m "first commit" git remote add origin <URL> git push origin -u master
删除已提交的文件或文件夹(删除本地文件然后提交,远程repository也会删除)
git rm -rf file | "folder" git commit -m 'descriptiom' git push -u origin master
检查已有的配置信息
git config --list | git config -l
设置提交者名字
git config --global user.name "userName"
设置提交者邮箱
git config --global user.email "userEmailAdress"
如果remote已经存在,想要修改remote url
git remote -v 查看remote git remote origin 删除remote git remote set-url origin <URL>
从远程git服务器上更新资源
git pull
比较两个版本文件的差异(并且将差异生成文件)
git diff folder/file folder/file > diff.txt
分支
创建一个叫做"lee"的分支,并切换过去
git checkout -b lee
切换回主分支
git checkout master
把新建的分支删除
git branch -d lee
push分支到远端仓库前,该分支不被人所见到
git push origin <branch>
改变分支名称
git branch -m old_name new_name
删除一个远程分支
git push origin --delete <branchName>
删除本地分支
git branch -D branchName
合并分支
有master分支创建develop分支 git checkout -b develop master 编辑develop后要合并分支 1、切换到master分支 git checkout master 2、合并develop分支到master git merge --no-ff develop
tag
创建tag
git tag [tagName] git tag -a [tagName] -m 'my version 1.4'
推送到服务器
1、推送所有tag git push --tags 2、单个推送tag git push origin tagName
删除tag
git push origin --delete tag [tagName]