天天看点

学习GIT相关指令Git相关指令

Git相关指令

最近感觉学习的git相关知识太过Low,整理一下相关的知识点(如果有错误,请在下方评论区指出)

git官网

学习GIT相关指令Git相关指令
下面会列出部分git知识点,带你走一遍git的基础操作
  • git init 相关知识
git-init - Create an empty Git repository or reinitialize an existing one
使用git init指令, 会在本地创建一个空的git代码仓库或者重新初始化当前目录下现有的git项目库
📧 Tip: 当当前目录已经被init的时候,执行git init指令会报错,可以先在bash控制台下执行

rm -rf .git

,删除已有的git项目地址

在bash下执行

git init --help

指令,得到相关的git init下的指令概览

git init [-q | --quiet] [--bare] [--template=<template_directory>]
                 [--separate-git-dir <git dir>]
                 [--shared[=<permissions>]] [directory]
           

下面是git init的相关指令列表

指令 含义
git init 初始化git项目, 在当前目录下面创建一个git本地仓库
  • git clone 相关知识
git-clone - Clone a repository into a new directory
git clone指令,clone一个远程仓库到本地新目录中

在bash下执行

git clone --help

指令,得到相关的git clone下的指令概览

git clone [--template=<template_directory>]
                 [-l] [-s] [--no-hardlinks] [-q] [-n] [--bare] [--mirror]
                 [-o <name>] [-b <name>] [-u <upload-pack>] [--reference <repository>]
                 [--dissociate] [--separate-git-dir <git dir>]
                 [--depth <depth>] [--[no-]single-branch] [--no-tags]
                 [--recurse-submodules[=<pathspec>]] [--[no-]shallow-submodules]
                 [--jobs <n>] [--] <repository> [<directory>]
           

下面是git clone的相关指令列表

指令 含义
git clone [url] 将远程仓库的代码copy到本地<.git自动带入>
git clone [url] [别名 or copy到本地目录的名称] 将远程仓库的代码copy到本地,并支持自定义本地同步远程项目的目录名称<.git自动带入>
  • git add 相关知识
git-add - Add file contents to the index

在bash下执行

git add --help

指令,得到相关的git add下的指令概览

git add [--verbose | -v] [--dry-run | -n] [--force | -f] [--interactive | -i] [--patch | -p]
                 [--edit | -e] [--[no-]all | --[no-]ignore-removal | [--update | -u]]
                 [--intent-to-add | -N] [--refresh] [--ignore-errors] [--ignore-missing] [--renormalize]
                 [--chmod=(+|-)x] [--] [<pathspec>...]
           

下面是git add的相关指令列表

指令 含义
git add . or git add -A 将本地代码添加到缓存中
git add [文件A] [文件B] … 指定某个文件添加到缓存中
git add [文件夹名字] 指定某目录下的所有文件都添加到缓存中
  • git status 相关知识
git-status - Show the working tree status
执行git status 指令,回去检查本地的工作区间<非缓存区>的diff树

在bash下执行

git status --help

指令,得到相关的git status下的指令概览

下面是git status的相关指令列表

指令 含义
git status 查看在你上次提交之后是否有对文件进行再次修改
  • git commit 相关知识
git-commit - Record changes to the repository
git commit 指令会记录本地改动跟版本库的差异

在bash下执行 git commit --help 指令,得到相关的git commit下的指令概览

git commit [-a | --interactive | --patch] [-s] [-v] [-u<mode>] [--amend]
                  [--dry-run] [(-c | -C | --fixup | --squash) <commit>]
                  [-F <file> | -m <msg>] [--reset-author] [--allow-empty]
                  [--allow-empty-message] [--no-verify] [-e] [--author=<author>]
                  [--date=<date>] [--cleanup=<mode>] [--[no-]status]
                  [-i | -o] [-S[<keyid>]] [--] [<file>...]
           

下面是git commit的相关指令列表

指令 含义
git commit -m [这个版本的修改描述] 将本地的修改记录到缓存中,并给这段修改的相关的文件,打上标签,说明这个版本修改的内容
git commit --amend -m [描述] 将本地所有commit 或 commit 的修改内容,统一打上一个共同的标签
  • git pull 相关知识
git-pull - Fetch from and integrate with another repository or a local branch
git pull指令,从其他存储库或本地分支获取并集成

在bash下执行 git pull --help 指令,得到相关的git pull下的指令概览

下面是git pull的相关指令列表

指令 含义
git pull 同步远程分支的代码,默认是同分支的代码
git pull origin [远程仓库分支名] 同步远程某具体仓库的代码到本地
  • git push 相关知识
git-push - Update remote refs along with associated objects
git push指令,会更新本地的代码到远程仓库中

在bash下执行 git push --help 指令,得到相关的git push下的指令概览

git push [--all | --mirror | --tags] [--follow-tags] [--atomic] [-n | --dry-run] [--receive-pack=<git-receive-pack>]
                  [--repo=<repository>] [-f | --force] [-d | --delete] [--prune] [-v | --verbose]
                  [-u | --set-upstream] [-o <string> | --push-option=<string>]
                  [--[no-]signed|--signed=(true|false|if-asked)]
                  [--force-with-lease[=<refname>[:<expect>]]]
                  [--no-verify] [<repository> [<refspec>...]]
           

下面是git push的相关指令列表

指令 含义
git push 将本地代码的修改提交推送到当前分支同步的远程分支上
git push origin [远程分支名] 将本地代码的修改提交推送到远程某分支
  • git stash 相关知识
git-stash - Stash the changes in a dirty working directory away
git stash指令将本地的更改,隐藏到脏工作目录中

在bash下执行 git stash --help 指令,得到相关的git stash下的指令概览

指令 含义
git stash 会把所有未提交的修改(包括暂存的和非暂存的)都保存起来,用于后续恢复当前工作目录
git stash save [暂存内容的标记,用于提取] 会把所有未提交的修改(包括暂存的和非暂存的)都保存起来,用于后续恢复当前工作目录,给每个stash加一个message标记,用于记录版本
git stash pop [message标记] 恢复上一个缓存的工作目录的内容
git stash apply [message标记] 将缓存堆栈中的stash多次应用到工作目录中,但并不删除stash拷贝
git stash list 查看现有的所有stash缓存list
git stash drop [message标记] 移除某stash缓存区
git stash show [message标记] 查看某stash与现在代码的diff