准备工作
生成公钥:
ssh-keygen
复制以下SSH公钥到对应地方:
cat ~/.ssh/id_rsa.pub
测试连接是否成功:
ssh -T git@github.com
日常指令
Command | Annotation |
---|---|
git | 简洁地查看所有指令 |
git help _command | 显示command的help |
git _command --help | 显示command的help |
git ls-files | 查看本仓库所有已存放的文件(包括子目录下的) |
git status | 查看本仓库还没记录的文件变化 |
touch _file | 新建文件 |
git add _file | 将工作文件修改提交到本地暂存区 |
git add . | 将所有修改过的工作文件提交暂存区 |
git add --all | 将所有删除工作提交暂存区 |
git add --all . | 将所有删除工作提交暂存区 |
git rm _file | 从版本库中删除文件 |
git reset _file | 从暂存区恢复到工作文件 |
git reset --hard _hash | 恢复哈希值所对应的目标时间点 |
git reset origin/HEAD | 恢复最后一次提交的状态 |
git revert HEAD | 恢复最后一次提交的状态 |
git diff _file | 比较当前文件和暂存区文件差异 |
git diff _id1 _id2 | 比较两次提交之间的差异 |
git diff _branch1 _branch2 | 在两个分支之间比较 |
git log | 查看提交记录 |
git log --graph | 图表形式查看分支 |
git log --pretty=short | 只显示提交信息的第一行 |
git log _file | 查看某文件每次提交记录 |
git branch -r | 查看远程分支 |
git branch -a | 查看本地和远程分支 |
git branch -d | 删除本地分支 |
git push origin --delete _branch | 删除远程分支 |
git check _branch | 切换分支 |
git merge _branch | 将某分支合并到当前分支 |
git pull | 抓取远程仓库所有分支更新并合并到本地 |
git pull --no-ff | 抓取远程仓库所有分支更新并合并到本地,不要快进合并 |
git fetch origin | 抓取远程仓库更新 |
git merge origin/_branch | 将远程某分支合并到本地当前分支 |
git --version | 查看当前git版本 |
git config --global push.default simple | 设置 push 的模式为 simple |
git push --set-upstream origin wei | 在远程仓库新建分支并把本地branch给push上去 |
git push | push所有分支 |
git push origin _branch | 将本地某分支推到远程某分支 |
git push origin _branch --force | 暴力push(可用于reset之后的push) |
git push -f origin _branch | 暴力push(可用于reset之后的push) |
git push -u origin _branch | 将本地主分支推到远程(如无远程主分支则创建,用于初始化远程仓库) |
git remote -v | 查看远程服务器地址和仓库名称 |
git remote update origin --prune | 更新远程分支列表 |
git remote show origin | 查看远程服务器仓库状态 |
git remote add origin git@github:user/first.git | 添加远程仓库地址 |
git remote set-url origin git@github.com:user/first.git | 设置远程仓库地址(用于修改远程仓库地址) |
git remote rm origin | 删除origin |
git remote rm _repository | 删除远程仓库 |
git blame _file | 得到某文件的每一行的详细修改信息:包括SHA串,日期和作者 |
全部指令:
$ git
usage: git [--version] [--help] [-C <path>] [-c name=value]
[--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
[-p|--paginate|--no-pager] [--no-replace-objects] [--bare]
[--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
<command> [<args>]
The most commonly used git commands are:
add Add file contents to the index
bisect Find by binary search the change that introduced a bug
branch List, create, or delete branches
checkout Checkout a branch or paths to the working tree
clone Clone a repository into a new directory
commit Record changes to the repository
diff Show changes between commits, commit and working tree, etc
fetch Download objects and refs from another repository
grep Print lines matching a pattern
init Create an empty Git repository or reinitialize an existing one
log Show commit logs
merge Join two or more development histories together
mv Move or rename a file, a directory, or a symlink
pull Fetch from and integrate with another repository or a local branch
push Update remote refs along with associated objects
rebase Forward-port local commits to the updated upstream head
reset Reset current HEAD to the specified state
rm Remove files from the working tree and from the index
show Show various types of objects
status Show the working tree status
tag Create, list, delete or verify a tag object signed with GPG
'git help -a' and 'git help -g' lists available subcommands and some
concept guides. See 'git help <command>' or 'git help <concept>'
to read about a specific subcommand or concept.