当前位置: 首页 > news >正文

Git命令速查手册

git init在指定的目录下创建一个空的git repo。不带参数将在当前目录下创建一个git repo。Create empty Git repo in specified directory. Run with no arguments to initialize the current directory as a git repository.
.git clone克隆一个指定repo到本地。指定的repo可以是本地文件系统或者由HTTP或SSH指定的远程路径。Clone repo located at <repo> onto local machine. Original repo can be located on the local filesystem or on a remote machine via HTTP or SSH.
git configuser.name针对当前repo配置用户名。使用--global 参数将配置全局用户名。Define author name to be used for all commits in current repo. Devs commonly use --global flag to set config options for current user.
git add将指定目录的所有修改加入到下一次 commit中。把<directory>替换成<file>将添加指定文件的修改。Stage all changes in <directory> for the next commit. Replace <directory> with a <file> to change a specific file.
git commit -m提交暂存区的修改,使用指定的<message>作为提交信息,而不是打开文本编辑器输入提交信息。Commit the staged snapshot, but instead of launching a text editor, use <message> as the commit message.
git status显示哪些文件已被staged、未被staged以及未跟踪(untracked)。List which files are staged, unstaged, and untracked.
git log以缺省格式显示全部commit历史。更多自定义参数请参考后续部分。Display the entire commit history using the default format. For customization see additional options.
GIT DIFF
git diff比较工作区和暂存区的修改。Show unstaged changes between your index and working directory.
git diff HEAD比较工作区和上一次commit后的修改。Show difference between working directory and last commit.
git diff --cached比较暂存区和上一次commit后的修改。Show difference between staged changes and last commit
UNDOING CHANGES
git revert对指定<commit>创建一个undo的commit,并应用到当前分支。Create new commit that undoes all of the changes made in <commit>, then apply it to the current branch.
git reset将<file>从暂存区移除,但保持工作区不变。此操作不会修改工作区的任何文件。Remove <file> from the staging area, but leave the working directory unchanged. This unstagess a file without overwriting any changes.
REWRITING GIT HISTORY
git commit -m将当前staged修改合并到最近一次的commit中。Replace the last commit with the staged changes and last commit combined.
git merge基于<base>对当前分支进行rebase。Rebase the current branch onto <base>. <base> can be a commit ID, branch name, a tag, or a relative reference to HEAD.
git rebase基于<base>可以是commit、分支名称、tag或相对于HEAD的commit。Show a log of changes to the local repository's HEAD.
git reflog显示本地repo的所有commit日志。Show a log of changes to the local repository's HEAD.
GIT BRANCHES
git branch显示本地repo的所有分支。List all of the branches in your repo.
git switch -c创建并切换到一个新的名为<branch>的分支。去掉<参数将切换到一个已有分支。Create and switch to a new branch named <branch>. Drop the <c> flag to switch to an existing branch.
git merge将指定<branch>分支合并到当前分支。Merge <branch> into the current branch.
REMOTE REPOSITIONS
git remote add添加一个新的远程连接。添加后可使用<name>作为指定<url>远程连接的名称。Create a new connection to a remote repo. After adding a remote, you can use <name> as a shortcut for <url> in other commands.
git fetch从指定<remote>抓取指定<branch>的所有的 commit到本地repo。去掉<branch>将抓取远程所有分支的修改。Fitches a specific <branch>, from the repo. Leave off <branch> to fetch all remote refs.
git pull从指定<remote>抓取所有分支的commit并立刻合并到本地repo。Fetch the specified remote's copy of current branch and immediately merge it into the local copy.
git push将本地指定<branch>推送到指定远程<remote>。如果远程没有对应的分支,将自动在远程创建此分支。Push the branch to <remote>, along with necessary commits and objects. Creates named branch in the remote repo if it doesn't exist.
GIT CONFIG
git config -- global user.name配置当前用户名,使用--global参数将针对当前系统登录用户生效。Define the author name to be used for all commits by the current user.
git config -- global user.email配置当前用户Email。Define the author email to be used for all commits by the current user.
git config -- global alias.配置一个git命令的快捷方式。例如:配置"alias.glog log --graph --online"使"git glog"相当于"git log --graph --online".Create shortcut for a Git command. E.g. alias.glog "log --graph --online" will set "git glog" equivalent to "git log --graph --online".
git config -- system core.editor配置文本编辑器,例如vi,在必要时自动打开此文本编辑器。Set text editor used by commands for all users on the machine. <editor> arg should be the command that launches the desired editor (e.g., vi).
git config -- global --edit打开当前用户的git全局配置并编辑。Open the global configuration file in a text editor for manual editing.
GIT LOG
git log --limit限制log的显示数量。例如:"git log -5"仅显示最新5条commit。Limit number of commits by <limit>. E.g. "git log -5" will limit to 5 commits.
git log --oneline每行显示一条commit。Condense each commit to a single line.
git log --author= "<pattern>"按提交者名字搜索并显示commit。Search for commits by a particular author.
git log --grep= "<pattern>"按指定内容搜索并显示commit。Search for commits with a commit message that matches <pattern>.
git log <since>..<until>显示指定范围的commit。范围参数可以是 commit ID, 分支名称、HEAD或任意相对位置。Show commits that occur between <since> and <until>. Args can be a commit ID, branch name, HEAD, or any other kind of revision reference.
git log --hard将当前分支回滚到指定<commit>,清除暂存区的修改,但保持工作区状态不变。Same as previous, but resets both the staging area & working directory to match. Deletes uncommitted changes, and all commits after <commit>.
git reset --hard将当前分支回滚到指定<commit>,清除暂存区的修改,并强制删除所有工作区的修改。--graph flag draws a text based graph of commits on left side of commit msgs.
GIT RESET
git reset移除所有暂存区的修改,但不会修改工作区。Reset staging area to match most recent commit, but leave the working directory unchanged.
git reset --hard移除所有暂存区的修改,并强制删除所有工作区的修改。Reset staging area and working directory to match most recent commit and overwrites all changes in the working directory.
git reset <commit>将当前分支回滚到指定<commit>,清除暂存区的修改,但保持工作区状态不变。Move the current branch tip backward to <commit>, reset the staging area to match, but leave the working directory alone.
git reset --hard将当前分支回滚到指定<commit>,清除暂存区的修改,并强制删除所有工作区的修改。Same as previous, but resets both the staging area & working directory to match. deletes uncommitted changes, and all commits after <commit>.
GIT REBASE
git rebase -i <base>以交互模式对当前分支做rebase。Interactively rebase current branch onto <base>. Launches editor to enter commands for how each commit will be transferred to the new base.
GIT PULL
git pull --rebase抓取所有远程分支,并以rebase模式并入本地repo而不是merge。Fetch the remote's copy of current branch and rebases into the local copy. Uses git rebase instead of merge to integrate the branches.
GIT PUSH
git push <remote> --force将本地分支推送到远程。不要使用--force参数,除非你完全明白此操作的后果。Forces the git push even if it results in a non-fast-forward merge. Do not use the -- force flag unless you're absolutely sure you know what you're doing.
git push <remote> --tags使用push命令并不会自动将本地tag推送到远程。加上-tags参数会将所有本地tag推送到远程。Tags aren't automatically pushed when you push a branch or use the --all flag. The --tags flag sends all of your local tags to the remote repo.
http://www.dtcms.com/a/577097.html

相关文章:

  • 随机链表的复制 (带random的链表深度拷贝)| C语言实现
  • 大仓库推到GitHub大踩坑-Git LFS从安装到使用
  • 宁夏制作网站公司网站仿静态和静态的区别
  • 【App开发】02:Android Studio项目环境设置
  • 初识MYSQL —— 复合查询
  • 有网站可以接设计的单子做吗招投标网站
  • 基于 WPS TOROW 函数实现 VLOOKUP:多行多列转一行
  • 编译SQLite 3.51源码并体验新功能
  • CMP(类Cloudera CDP 7.3 404版华为泰山Kunpeng)和Apache Doris的对比
  • 水果电商网站建设相关文献163企业邮箱登入口
  • HarmonyOS黑马云音乐项目增加网络听歌功能(一、轮播图的实现)
  • 二、Netty-NIO核心原理详解(NIO核心组件:Buffer、Channel、Selector)
  • 网站短信接口怎么做网站开发环境有什么
  • 网站建设客户开发方案网站建设公司介绍
  • 矩阵乘法优化
  • sward零基础学习,如何在sward文档中集成Kanass事项
  • React使用笔记(持续更新中)
  • ArkTS运行时
  • C语言递归宏详解
  • 指令微调(Instruction Tuning)
  • Linux 中 NIC(网络接口卡)和协议栈的区别以及DPDK
  • MATLAB实现贝叶斯回归预测
  • ZYNQ介绍
  • 【Python】-- 趣味代码 - Piano游戏
  • 解决使用EasyExcel导出带公式的excel,公式不自动计算问题
  • 展示型网站多少钱建设大型网站的公司
  • 前端FAQ: 描述⼀下你最近使⽤过的前端框架,并解释为何选择它们?
  • [特殊字符] 微前端部署实战:Nginx 配置 HTTPS 与 CORS 跨域解决方案(示例版)
  • 短视频矩阵系统搭建指南:源码部署与全流程解析
  • 李沐动手学深度学习笔记(1)