Open J-DuYa opened 3 years ago
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 commit -m 'xxx' --no-verify | 强制性commit文件 |
git-pull - Fetch from and integrate with another repository or a local branch
git pull指令,从其他存储库或本地分支获取并集成
在bash下执行 git pull --help 指令,得到相关的git pull下的指令概览
git pull [<options>] [<repository> [<refspec>...]]
下面是git pull的相关指令列表
指令 | 含义 |
---|---|
git pull | 同步远程分支的代码,默认是同分支的代码 |
git pull origin [远程仓库分支名] | 同步远程某具体仓库的代码到本地 |
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-remote - Manage set of tracked repositories
git remote指令 管理跟踪存储库集
在bash下执行 git remote --help 指令,得到相关的git remote下的指令概览
git remote [-v | --verbose]
git remote add [-t <branch>] [-m <master>] [-f] [--[no-]tags] [--mirror=<fetch|push>] <name> <url>
git remote rename <old> <new>
git remote remove <name>
git remote set-head <name> (-a | --auto | -d | --delete | <branch>)
git remote set-branches [--add] <name> <branch>...
git remote get-url [--push] [--all] <name>
git remote set-url [--push] <name> <newurl> [<oldurl>]
git remote set-url --add [--push] <name> <newurl>
git remote set-url --delete [--push] <name> <url>
git remote [-v | --verbose] show [-n] <name>...
git remote prune [-n | --dry-run] <name>...
git remote [-v | --verbose] update [-p | --prune] [(<group> | <remote>)...]
下面是git remote的相关指令列表 | 指令 | 含义 |
---|---|---|
git remote add origin master [远程仓库的ssh或者url] | 将本地git仓库指向指定某远程仓库 |
git-stash - Stash the changes in a dirty working directory away
git stash指令将本地的更改,隐藏到脏工作目录中
在bash下执行 git stash --help 指令,得到相关的git stash下的指令概览
下面是git stash的相关指令列表
git stash list [<options>]
git stash show [<stash>]
git stash drop [-q|--quiet] [<stash>]
git stash ( pop | apply ) [--index] [-q|--quiet] [<stash>]
git stash branch <branchname> [<stash>]
git stash [push [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]
[-u|--include-untracked] [-a|--all] [-m|--message <message>]
[--] [<pathspec>...]]
git stash clear
git stash create [<message>]
git stash store [-m|--message <message>] [-q|--quiet] <commit>
下面是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 | |
git stash clear | 清除stash缓存中所有的记录 |
git-reset - Reset current HEAD to the specified state
git-reset 重置当前head的state
在bash下执行 git reset --help 指令,得到相关的git reset下的指令概览
git reset [-q] [<tree-ish>] [--] <paths>...
git reset (--patch | -p) [<tree-ish>] [--] [<paths>...]
git reset [--soft | --mixed [-N] | --hard | --merge | --keep] [-q] [<commit>]
下面是git reset的相关指令列表 | 指令 | 含义 |
---|---|---|
git reset --hard | 重置当前本地代码库到上一次提交的版本库 [当前库] ---> [上一个版本库] | |
git reset --hard [commit ID] | 重置当前版本到指定的版本 commit ID 可以根据 指令git log or git reflog 查询 |
git-log - Show commit logs
在bash下执行 git log --help 指令,得到相关的git log下的指令概览
git log [<options>] [<revision range>] [[--] <path>...]
下面是git log的相关指令列表 | 指令 | 含义 |
---|---|---|
git log | 查看远程版本库的所有提交记录 |
git-reflog - Manage reflog information
在bash下执行 git reflog --help
,得到相关的git reflog下的指令概览
git reflog <subcommand> <options>
下面是git reflog的相关指令列表
指令 | 含义 |
---|---|
git reflog | 显示整个本地仓储的commit, 包括所有branch的commit, 甚至包括已经撤销的commit, 只要HEAD发生了变化, 就会在reflog里面看得到. git log只包括当前分支的commit |
git-revert - Revert some existing commits
在bash下执行git revert --help
,得到相关的git revert下的指令概览
git-revert - Revert some existing commits
git revert [--[no-]edit] [-n] [-m parent-number] [-s] [-S[<keyid>]] <commit>...
git revert --continue
git revert --quit
git revert --abort
下面是git revert的相关指令列表 | 指令 | 含义 |
---|---|---|
git revert -n [commit ID] | 重做某个commit提交的内容 |
在主分支,创建新分支并且切到新分支开发
git checkout -b feature-login 在feature-login下写相关代码,写完了,提交 (feature-login)git add . git commit -m '登录' git push origin feature-login
主管正常合并分支
(master)git fetch git branch git checkout feature-login (feature-login) git pull origin feature-login (拉取最新代码) git checkout master (master) git merge feature-login git push origin master
主管合并分支有冲突
(master) git merge 'feature-register' 报错CONFLICT ... 冲突文件解决冲突代码 git add . git commit -m 'feature-register' git merge 'feature-register'(会提示是最新代码不需要合并了) git push origin master
不小心在master分支上写了很多代码 (master) 此时不能直接切换分支
git stash(修改的记录会放到一边,只剩下新增的文件,可切换分支) git checkout -b feature-logout (feature-logout) git stash pop(将之前的修改在拿出来) git add . git commit -m '注销' git push origin feature-logout
git-branch - List, create, or delete branches
git branch 返回一个列表或创建或删除分支
在bash下执行git branch --help
,得到相关的git branch下的指令概览
git branch [--color[=<when>] | --no-color] [-r | -a]
[--list] [-v [--abbrev=<length> | --no-abbrev]]
[--column[=<options>] | --no-column] [--sort=<key>]
[(--merged | --no-merged) [<commit>]]
[--contains [<commit]] [--no-contains [<commit>]]
[--points-at <object>] [--format=<format>] [<pattern>...]
git branch [--track | --no-track] [-f] <branchname> [<start-point>]
git branch (--set-upstream-to=<upstream> | -u <upstream>) [<branchname>]
git branch --unset-upstream [<branchname>]
git branch (-m | -M) [<oldbranch>] <newbranch>
git branch (-c | -C) [<oldbranch>] <newbranch>
git branch (-d | -D) [-r] <branchname>...
git branch --edit-description [<branchname>]
下面是git branch的相关指令列表
指令 | 含义 |
---|---|
git branch -a | 查看本地和远程所有的分支 |
git branch -D [branch 名称] | 删除本地某个分支 |
git-checkout - Switch branches or restore working tree files
在bash下执行git checkout --help,得到相关的git checkout下的指令概览
git checkout [-q] [-f] [-m] [<branch>]
git checkout [-q] [-f] [-m] --detach [<branch>]
git checkout [-q] [-f] [-m] [--detach] <commit>
git checkout [-q] [-f] [-m] [[-b|-B|--orphan] <new_branch>] [<start_point>]
git checkout [-f|--ours|--theirs|-m|--conflict=<style>] [<tree-ish>] [--] <paths>...
git checkout [<tree-ish>] [--] <pathspec>...
git checkout (-p|--patch) [<tree-ish>] [--] [<paths>...]
下面是git checkout的相关指令列表 | 指令 | 含义 |
---|---|---|
git checkout [branch name] | 切换到指定的分支 | |
git checkout -b [local name] [remote name] | 将远程分支的代码拉取到本地,在本地建一个本地分支 |
Git相关指令
最近感觉学习的git相关知识太过Low,整理一下相关的知识点(如果有错误,请在下方评论区指出)
git官网
在bash下执行
git init --help
指令,得到相关的git init下的指令概览在bash下执行
git clone --help
指令,得到相关的git clone下的指令概览在bash下执行
git add --help
指令,得到相关的git add下的指令概览在bash下执行
git status --help
指令,得到相关的git status下的指令概览