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)
相關文章
相關標籤/搜索