zoukankan      html  css  js  c++  java
  • 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)
    
  • 相关阅读:
    《网络攻防第四周作业》
    《网络攻防第三周作业》20179313
    15.javaweb XML详解教程
    小程序新功能:直接进入内嵌网页!
    为什么要创业?听听扎克伯格怎么说
    面试官:“还有什么问题问我吗?”我...
    双十一为何规则复杂,套路多多
    如何设置电信光猫?图解手把手教你(超级详细)
    14.javaweb AJAX技术详解
    android黑科技系列——自动注入代码工具icodetools
  • 原文地址:https://www.cnblogs.com/nzbin/p/9050541.html
Copyright © 2011-2022 走看看