Git相關指令
最近感覺學習的git相關知識太過Low,整理一下相關的知識點(如果有錯誤,請在下方評論區指出)
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 |