前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >git:指令备忘录

git:指令备忘录

作者头像
JNingWei
发布2018-09-28 17:39:38
4720
发布2018-09-28 17:39:38
举报
文章被收录于专栏:JNing的专栏JNing的专栏

准备工作

生成公钥:

代码语言:javascript
复制
ssh-keygen

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

代码语言:javascript
复制
cat ~/.ssh/id_rsa.pub

测试连接是否成功:

代码语言:javascript
复制
ssh -T git@github.com

日常指令

Command

Annotation

git

简洁地查看所有指令

git help _command

显示command的help

git _command –help

显示command的help

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 -d

删除分支

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

git push -u origin _branch

将本地主分支推到远程(如无远程主分支则创建,用于初始化远程仓库)

git push origin –delete _branch

删除远程分支

git remote -v

查看远程服务器地址和仓库名称

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串,日期和作者


  全部指令:

代码语言:javascript
复制
$ 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:



本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017年06月20日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 准备工作
  • 日常指令
    • Ref:
    领券
    问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档