GIT常用命令总结
文章目录
命令介绍
$ git --help
usage: git [--version] [--help] [-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>]
The most commonly used git commands are:
常用命令:
add Add file contents to the index
添加文件
bisect Find by binary search the change that introduced a bug
branch List, create, or delete branches
列表,创建,或删除分支
checkout Checkout a branch or paths to the working tree
检出分支或目录到工作目录
clone Clone a repository into a new directory
克隆一个数据源到新的文件夹
commit Record changes to the repository
提交修改到数据源
diff Show changes between commits, commit and working tree, etc
fetch Download objects and refs from another repository
grep Print lines matching a pattern
init Create an empty Git repository or reinitialize an existing one
log Show commit logs
merge Join two or more development histories together
mv Move or rename a file, a directory, or a symlink
pull Fetch from and merge with another repository or a local branch
push Update remote refs along with associated objects
rebase Forward-port local commits to the updated upstream head
reset Reset current HEAD to the specified state
rm Remove files from the working tree and from the index
show Show various types of objects
status Show the working tree status
tag Create, list, delete or verify a tag object signed with GPG
git remote (远程管理)
git remote
$ git remote
origin
git pull (拉取代码)
git checkout master #先选择分支master
git pull ##更新master分支到本地
git 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] [--push-option=<string>]
[--[no-]signed|--signed=(true|false|if-asked)]
[--force-with-lease[=<refname>[:<expect>]]]
[--no-verify] [<repository> [<refspec>…]]
介绍
git push 推送分支到远程服务器
git push origin test # 将test分支推送到origin远程
git push origin --delete 删除远程分支
git push origin --delete test # 删除远程origin上的test分支
git checkout 命令(检出)
说明
NAME
git-checkout - Switch branches or restore working tree files
SYNOPSIS
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 检出分支
git checkout test
git checkout -b 检出并创建新的分支
git checkout -b test
相当于
git branch test
git checkout test
git 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 test创建分支
git branch test # 创建test分支
git granch查看当前分支
$ git branch
* master # * 代表当前所在分支
pub
git branch --list 查看分支列表
git branch --list //查看分支列表
$ git branch --list
test
* master
git branch -a 查看分支详细
$ git branch -a
master
* pub
remotes/origin/HEAD -> origin/master
remotes/origin/fuzhou
remotes/origin/master
remotes/origin/pub
git checkout 切换分支
$ git checkout test
Switched to branch 'test' # 切换到分支
git branch -d 删除分支
git branch -d test
git commit 提交
git commit 需要结合git add一起使用
git add 添加已经修改的代码,然后再用git commit 提交
git add test.html
git commit -m "修改了test.html" # 提交到本地工作目录
git push origin test # 提交到远程服务器
git commit -m 提交代码带注释
git commit -m "测试提交" # 提交代码, -m "" 代表的是注释