外观
idea.txt 忽视 idea.txt 文件.gitignore 忽视.gitignore 文件css/index.js 忽视 css 下的 index.jscss/*.js 忽视 css 下的所有 js 文件css 忽视 css 文件夹//设置用户名
git config --global user.name 用户名
//设置邮箱
git config --global user.email 邮箱
//查看配置信息
git config --listgit init//将选择文件添加到暂存区/文件夹/所有的js文件
git add 文件名称/文件夹名称/*.js
//添加当前目录下的所有文件
git add ./-A/--all//将文件从暂存区提交到仓库
git commit -m 添加说明
// 修改上一次提交说明
git commit --amend -m 提交说明//查看提交的日志
git log
//查看所有的版本信息,回退之后也可以查看
git reflog
//查看工作区与暂存区的不同
git diff
//查看工作区域仓库区的不同
git diff --cached
//查看工作区域仓库区的不同,最新提交比较
git diff HEAD
//比较两次版本的不同
git diff 版本号 版本号//回退到指定版本号
git reset --hard 版本号
//回退到上一次提交/上上次提交/本次提交
git reset --hard head~1/head~2/head~0
// --hard 其他参数
// --soft 只重置仓库区
// --mixed 重置仓库区和暂存区
// --hard 重置仓库区暂存区和工作区注意
在 git 中,有一个特殊分支 HEAD 永远指向当前分支
//查看分支
git branch
//创建分支
git branch 分支名称
//切换分支
git checkout 分支名称
//创建新分支并切换到该分支
git chekcout -b 分支名称//删除分支
git branch -d 分支名称
//合并分支 将其他分支的内容合并到当前分支
git merge 分支名称注意
不能在当前分支删除当前分支,需要切换到其他分支才能删除
git clone 远程仓库地址// 克隆远程仓库指定分支到本地
git clone -b 远程分支名 仓库地址//拉取远程仓库代码
git pull 远程仓库地址 分支名称
//将本地仓库中代码提交到远程仓库
git push 远程仓库地址 分支名称//给远程仓库起一个别名
git remote 仓库别名 仓库地址
//删除别名
git remote remove 仓库别名git tag tag名称 -m tag备注git push origin --taggit pull origin --taggit tagcommit idgit show tag名称//版本回退
git reset --hard 提交commit-id
//创建分支并切换到新分支
git checkout -b 分支名称注意
通过标签回退版本后,需要创建一个新的分支,然后当前主干分支要立即回到原来的位置。在新的分支上修改代码
//切换到之前分支
git checkout 之前分支名称
//查看之前分支的原来位置提交id
git reflog
// 主分支回到原来提交位置
git reset --hard 原来提交commit-id后续,切换分支,在新建分支上修改代码
Git 储藏(stashing)是一种将当前工作进度保存起来的方法,以便可以切换到其他分支进行其他工作,而不会丢失当前的工作进度。
git stashgit stash listgit stash applygit stash dropgit stash popgit stash apply stash@{储藏编号}git stash drop stash@{储藏编号}git stash pop stash@{储藏编号}