【工具】Git使用
一:基本配置
git init: 初始化仓库
git clone: 从远程克隆仓库到本地
git add
git commit -m "xxx": 提交暂存区文件
二:config命令
配置文件:
system: /etc/gitconfig
global: #HOME/.gitconfig
[user] name = xxxx email = xxxx@163.com
local: $PROJECT/.git/config
[core] repositoryformatversion = 0 filemode = false bare = false logallrefupdates = true symlinks = false ignorecase = true [remote "origin"] url = git@github.com:skywind3000/awesome-cheatsheets.git fetch = +refs/heads/*:refs/remotes/origin/* [branch "master"] remote = origin merge = refs/heads/master
workree: git 2.6引入的特性
git config --list: 列出所有
user.name=xxxx user.email=xxxxxx@163.com core.repositoryformatversion=0 core.filemode=false core.bare=false core.logallrefupdates=true core.symlinks=false core.ignorecase=true remote.origin.url=git@github.com:skywind3000/awesome-cheatsheets.git remote.origin.fetch=+refs/heads/*:refs/remotes/origin/* branch.master.remote=origin branch.master.merge=refs/heads/master
三:查看状态&对比文件
git status: 查看状态
git status -s: 查看状态
git diff
git diff HEAD --
git diff --cached: 对比HEAD指针和暂存区
git diff --staged: 对比?
git diff --check
git diff --cached
四:查看提交历史
git log
git log -n: 查看n条提交记录
git log
git log --stat: 历次commit的文件变化
git log --shortstat: 只显示总文件和行数变化
git log --name-status: 显示新增、修改、删除的文件清单
git log commit..commit: 对比两次commit
git log -p: 历次commit的内容增删
git log -p -W: 历次commit的内容增删,同时显示上下文
二:删除&撤销&回退
git checkout --
git restore
git reset HEAD
git reset --hard HEAD^: 撤销git commit
git rm/add
git rm --cache
五:关联远程仓库
git remote add origin
git remote rm origin:
git push -u origin master:
git push origin master:
六:分支管理
git branch
git checkout
git switch
git checkout -b
git switch -b
git branch: 查看已有分支
git merger: 合并分支
git branch -d: 删除分支
七:暂存文件
git stash save: 暂存当前文件
git stash list: 列出暂存文件
git stash pop: 恢复现场
git stash apply: 恢复指定现场
git stash drop: 丢弃某个修改