简单概念

工作区: 本地电脑所能看到的目录。
版本库: 工作区有一个隐藏目录.git,这个不算工作区,而是Git的版本库。版本库中的stage比较重要的概念称作暂存区,master是默认创建的分支,head是指向master分支的指针
git add
命令是文件修改添加到暂存区。git commit
命令是把暂存区文件添加到当前分支,上图中为master。本地常用操作
新建分支并切换 git checkout -b branchName
新建本地分支git branch newBranch
切换分支git checkout newBranch
查看分支git branch
删除本地分支git barnch -d newBranch
查看未合并分支git branch --no-merged
合并分支到当前分支git merge branchName
版本回退git reset --hard 1234567
回退当前版本git reset --hard HEAD^
对比工作区git diff 123.txt
对比暂存区git diff --cached 123.txt
一行日志查看git log --pretty=oneline
查看所有分支的所有操作记录日志,包括删除的以及reset的内容git reflog
显示版本提交历史git log
查看当前文件cat 123.txt
放弃掉所有还没有加入到缓存区(就是 git add 命令)的修改git checkout .
修改上一次commit注释git commit --amend
弹出vim修改注释再wq保存
远程分支操作
克隆远程分支git clone -b remoteBranchName remotePath
拉取远程分支git pull origin remoteName
推送到远程分支git push origin remoteName
删除远程分支git branch origin -delete newBranch
列出已经存在的远程分支git remote
列出已经存在的远程分支详细信息git remote -v
添加远程库git remote add origin git@...
删除远程库git remote rm 别名
查看远程分支git branch -r
获取本地没有的远程分支
git fetch
git checkout -b newBranch origin/newBranch
比较分支差异
查看shang有,而master中没有git log shang ^master
查看master有,而上中没有git log master ^shang
查看shang中比master中多提交了哪些内容git log master...shang
显示出所有差异文件的详细差异git diff branch1 branch2
显示指定文件的详细差异git dif branch1 branch2 文件路径
复制shang分支的123.txt文件到master分支两步
git checkout master
切换到master分支git checkout shang 123.txt
BUG处理
保存现场git stash
保存现场并添加注释git stash save '注释'
恢复现场git stash pop
取出指定版本号的现场git stash apply stash@{1}
查询现场git stash list
删除指定版本号的现场git stash drop stash@{0}
清除全部现场git stash clear
git配置用户信息
查看配置git config --global --list
查看代理配置npm config get registry
查看npm配置npm config list
查看是否配置过两步
- 命令行中输入
cd ~/.ssh
- 命令行中输入
ls
查看密钥列表,看到有id_ras.pub文件说明已经配置过了
初次配置三步
git config --global user.name 'yourname'
git config --global user.email 'yourmail@xxxxx.com'
- 生成公钥(一路enter)
ssh-keygen -t rsa -C 'yourmail@xxxxx.com'