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 .
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 -m <msg>
reset
git reset [-q]
[<tree-ish>]
[--]
<paths>…
git reset (--patch | -p) [<tree-ish>] [--] [<paths>…]
git reset [--soft | --mixed [-N] | --hard | --merge | --keep] [-q] [<commit>]
# 回滚到某个 commit
git reset --hard [<commit>]
# 记录所有操作,可以找回丢失的 commit
git reflog
分支与合并
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] [-l] [-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 <branchname>
# 删除本地分支
git branch -d <branchname>
# 查看本地分支
git branch
# 查看所有(本地+远程)分支
git branch -a
# 删除远程分支
git push origin --delete <branchname>
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 -b <branchname>
merge
git merge [-n]
[--stat]
[--no-commit]
[--squash]
[--[no-]edit]
[-s <strategy>]
[-X <strategy-option>]
[-S[<keyid>]]
[--[no-]allow-unrelated-histories]
[--[no-]rerere-autoupdate]
[-m <msg>]
[-F <file>]
[<commit>…]
git merge --abort
git merge --continue
分享及更新项目
fetch
git fetch [<options>] [<repository> [<refspec>…]]
git fetch [<options>] <group>
git fetch --multiple [<options>] [(<repository> | <group>)…]
git fetch --all [<options>]
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 origin dev(local):dev(remote)
# 删除远程分支
git push origin :dev(remote)
感谢您的阅读,如果您对我的文章感兴趣,可以关注我的博客,我是叙帝利,下篇文章再见!
开发低代码平台的必备拖拽库 https://github.com/ng-dnd/ng-dnd
低代码平台必备轻量级 GUI 库 https://github.com/acrodata/gui
适用于 Angular 的 CodeMirror 6 组件 https://github.com/acrodata/code-editor
基于 Angular Material 的中后台管理框架 https://github.com/ng-matero/ng-matero
Angular Material Extensions 扩展组件库 https://github.com/ng-matero/extensions
Unslider 轮播图插件纯 JS 实现 https://github.com/nzbin/unsliderjs
仿 Windows 照片查看器插件 https://github.com/nzbin/photoviewer
仿 Windows 照片查看器插件 jQuery 版 https://github.com/nzbin/magnify
完美替代 jQuery 的模块化 DOM 库 https://github.com/nzbin/domq
简化类名的轻量级 CSS 框架 https://github.com/nzbin/snack
与任意 UI 框架搭配使用的通用辅助类 https://github.com/nzbin/snack-helper
单元素纯 CSS 加载动画 https://github.com/nzbin/three-dots
有趣的 jQuery 卡片抽奖插件 https://github.com/nzbin/CardShow
悬疑科幻电影推荐 https://github.com/nzbin/movie-gallery
锻炼记忆力的小程序 https://github.com/nzbin/memory-stake