Git是一个开源的分布式版本控制系统,用于敏捷高效地处理任何或小或大的项目。
git基本指令
- git status git仓库当前的状态,比如仓库类的文件有变动或者有新的文件没有加入进来等等
- git add file/directory 将当前文件保存,但是没有提交,不会生成版本号,
- git commit -m “description” 提交操作,会生成版本号(随机的),description对这个版本进行描述
- git log/reflog 查看历史版本信息
- git reset --hard version 跳转到某个版本
- git clone url 从远程克隆一个副本到本地
- git init 初始化一个git仓库
- git rm -r --cached . (清空git add . 缓存, 清空掉 git status cached 数据), 注意后面有点
git 分支管理##
- git checkout [-b] branchName [remote/branchName] 跳转到某个分支,[-b]创建某个分支 [remote/branchName]远程分支名
- git branch 查看所有分支
- git merge branchName 合并分支
- git branch -d branchName 删除分支,只是本地删除了
- git push origin --delete Chapater6 可以删除远程分支Chapater6
- git push remote branchName 向远程推送当前分支
- git checkout -b 本地分支名 origin/远程分支名(将远程git仓库里的指定分支拉取到本地(本地不存在的分支),如果不成功,我们需要先执行git fetch,然后再执行 git checkout -b 本地分支名 origin/远程分支名
- 将远程分支拉到本地(本地没有该分支)
我们需要:git fetch origin dev 命令来把远程分支拉到本地
然后使用:git checkout -b dev origin/dev在本地创建分支dev并切换到该分支
最后使用:git pull origin dev就可以把某个分支上的内容都拉取到本地了
github 使用
- git remote -v 查看所有远程信息
- git remote set-url origin xxxxx.git # 直接修改远程地址
- git remote rm origin # 删除现用的remote地址“origin”:
- git add remote userName url 添加远程并且为这个远程重命名
git remote add origin http://[email protected]:8080/gitblit/r/bbb.git
- git push remote branchName 向远程推送某个分支
- git pull remote branchName 与远程进行同步
- git stash 将现场存储起来 git stash pop 恢复现场
- git fetch remote branckName 与远程进行同步