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)
posted @ 2018-10-13 22:40  叙帝利  阅读(414)  评论(0编辑  收藏  举报