Git命令行使用

摘要:之前一直使用Eclipse中的GIt插件进行版本控制,忽略了Git命令行的使用,进入公司之后才发现开发中git命令使用的重要性,故通过查找资料,对Git命令行进行整理。

Git概述

Git是一个分布式版本控制系统,用于敏捷高效地处理任何或小或大的项目。其他版本控制系统包括CVS,SVN。

$ git

usage: git [- -version ] [- -help] [-C < path>] [-c name=value]
[- -exec-path [=< path>]] [- - html-path] [- - man-path] [- -info-path]
[-p | –paginate | - - no-pager] [- -no-replace-objects] [- - bare]
[- - git-dir=< path>] [- -work-tree=< path>] [–namespace=< name>]
< command> [< args>]

Git Reference

设置与配置(Setup and Config)

  1. git-config : 获取和设置仓库或全局选项
  2. git-help : 显示git的帮助信息

创建和获取项目(Getting and Creating Projects)

  1. git init : 创建一个新的Git仓库或初始化现有仓库
    git init [-q | –quiet] [–bare] [–template=< template_directory>]
    [–separate-git-dir < git dir>]
    [–shared[=< permissions>]] [directory]
  2. git clone:克隆一个仓库到当前目录下
    git clone [- -template=< template_directory>]
    [-l] [-s] [- -no-hardlinks] [-q] [-n] [–bare] [- -mirror]
    [-o < name>] [-b < name>] [-u < upload-pack>] [- -reference < repository>]
    [- -dissociate] [- -separate-git-dir < git dir>]
    [- -depth < depth>] [- -[no-]single-branch]
    [- -recursive | - -recurse-submodules] [–] < repository>
    [< directory>]

常用基本命令

  1. git add : 将文件添加到当前Git仓库的索引中,让Git进行管理
    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]
    [- -] [< pathspec>…​]
  2. git status : 查看当前Git仓库索引中文件的状态,是否被管理,修改等。
    git status [< options>…​] [- -] [< pathspec>…​]
  3. git diff : 对比本地仓库与远程仓库的变化
    git diff [options] [< commit>] [- -] [< path>…​]
    git diff [options] - -cached [< commit>] [- -] [< path>…​]
    git diff [options] < commit> [- -] [< path>…​]
    git diff [options] < blob> < blob>
    git diff [options] [- -no-index] [- -] < path> < path>
  4. 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>…​]
  5. 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>]
  6. git rm : 将文件从当前仓库管理的索引中移除
    git rm [-f | - -force] [-n] [-r] [- -cached] [- -ignore-unmatch] [–quiet] [- -] < file>…​
  7. git mv : 移动或重命名文件,目录或符号链接
    git mv < options>…​ < args>…​

分支与合并(Branching and Merging)

  1. git branch : 查看,删除,创建分支
    git branch [- -color[=< when>] | - -no-color] [-r | -a]
    [- -list] [-v [- -abbrev=< length> | - -no-abbrev]]
    [- -column[=< options>] | - -no-column]
    [(- -merged | - -no-merged | - -contains) [< commit>]] [- -sort=< key>]
    [- -points-at < object>] [< pattern>…​]
    git branch [- -set-upstream | - -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 (-d | -D) [-r] < branchname>…​
    git branch - -edit-description [< branchname>]
  2. 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 [-p|- -patch] [< tree-ish>] [- -] [< paths>…​]
  3. git merge : 合并分支
    git merge [-n] [- -stat] [- -no-commit] [- -squash] [- -[no-]edit]
    [-s < strategy>] [-X < strategy-option>] [-S[< keyid>]]
    [- -[no-]rerere-autoupdate] [-m < msg>] [< commit>…​]
    git merge < msg> HEAD < commit>…​
    git merge - -abort
  4. git mergetool : 运行合并和解决冲突的工具来解决合并冲突
    git mergetool [- -tool=< tool>] [-y | - -[no-]prompt] [< file>…​]
  5. git log : 查看提交更改记录
    git log [< options>] [< revision range>] [[\–] < path>…​]
  6. 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 [save [-p|- -patch] [-k|- -[no-]keep-index] [-q|- -quiet]
    [-u|- -include-untracked] [-a|–all] [< message>]]
    git stash clear
    git stash create [< message>]
    git stash store [-m|- -message < message>] [-q|- -quiet] < commit>
  7. git tag : 创建、列表、删除或验证一个GPG签署的标签对象
    git tag [-a | -s | -u < keyid>] [-f] [-m | -F < file>]
    < tagname> [< commit> | < object>]
    git tag -d < tagname>…​
    git tag [-n[< num>]] -l [- -contains < commit>] [- -points-at < object>]
    [- -column[=< options>] | - -no-column] [- -create-reflog] [- -sort=< key>]
    [- -format=< format>] [- -[no-]merged [< commit>]] [< pattern>…​]
    git tag -v < tagname>…​

共享和更新项目(Sharing and Updating Projects)

  1. git fetch : 从另一个仓库下载对象和参数
    git fetch [< options>] [< repository> [< refspec>…​]]
    git fetch [< options>] < group>
    git fetch - -multiple [< options>] [(< repository> | < group>)…​]
    git fetch - -all [< options>]
  2. git pull : 从其他仓库或本地分支中获取并整合进当前仓库
    git pull [options] [< repository> [< refspec>…​]]
  3. git push : 将当前提交的修改更新到远程绑定的仓库
    git push [- -all | - -mirror | - -tags] [- -follow-tags] [- -atomic] [-n | - -dry-run] [- -receive-pack=< git-receive-pack>]
    [- -repo=< repository>] [-f | - -force] [- -prune] [-v | - -verbose]
    [-u | - -set-upstream]
    [- -[no-]signed|- -sign=(true|false|if-asked)]
    [- -force-with-lease[=< refname>[:< expect>]]]
    [- -no-verify] [< repository> [< refspec>…​]]
  4. 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>)…​]
  5. git submodule : 初始化,更新或检查子模块

参考

  1. Git命令使用整理
  2. Git命令详解
  3. Git常用命令
  4. Git基本命令行操作
  5. Git-Reference

你可能感兴趣的:(其他)