git:指令备忘录

准备工作

生成公钥:

ssh-keygen

复制以下SSH公钥到对应地方:

cat ~/.ssh/id_rsa.pub

测试连接是否成功:

ssh -T git@github.com

日常指令

CommandAnnotation
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 pushpush所有分支
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.


Ref:



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值