一、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>]
These are common Git commands used in various situations:
start a working area (see also: git help tutorial)
clone Clone a repository into a new directory
init Create an empty Git repository or reinitialize an existing one
work on the current change (see also: git help everyday)
add Add file contents to the index
mv Move or rename a file, a directory, or a symlink
reset Reset current HEAD to the specified state
rm Remove files from the working tree and from the index
examine the history and state (see also: git help revisions)
bisect Use binary search to find the commit that introduced a bug
grep Print lines matching a pattern
log Show commit logs
show Show various types of objects
status Show the working tree status
grow, mark and tweak your common history
branch List, create, or delete branches
checkout Switch branches or restore working tree files
commit Record changes to the repository
diff Show changes between commits, commit and working tree, etc
merge Join two or more development histories together
rebase Forward-port local commits to the updated upstream head
tag Create, list, delete or verify a tag object signed with GPG
collaborate (see also: git help workflows)
fetch Download objects and refs from another repository
pull Fetch from and integrate with another repository or a local branch
push Update remote refs along with associated objects
'git help -a' and 'git help -g' list available subcommands and some
concept guides. See 'git help <command>' or 'git help <concept>'
to read about a specific subcommand or concept.
二、日常使用命令以及操作流程:
cd haier //跳转到本机指定目录“haier” (空文件夹)
git clone ssh://stash.lezhuan.io:7999/zla/rnhry.git // 从服务器上clone 一份代码 到“haier”文件夹中 ,项目名称“hmanager”
cd hmanager
//接下来使用git 命令
git branch //master 查看本地分支,一般只有master,当前分之在master
git branch -a // 查看所有分支,包括远程服务器上的分之
git checkout develop //切换分支
//编辑了文档
git status //查看你本地所有的更改
git add . //添加所有更改文档
git add "当前文件完整路径" // 添加某一文件
git commit -am ‘这次的更新内容’ //将上一步add的文档进行commit ,在本地对更改文档进行提交
git pull //从服务器拉最新代码下来
git push //将本地提交push到服务器,结束。
git checkout // 将本地未add的代码全部回滚原来版本,但是值得注意的是新添加的文件不会删除得手动删除
git reset head . // 撤销本地的add
git reset --hard “commit_id” // 撤销commit,git log(查看commit_id的命令)
//从服务器pull之后,自动跟本地代码进行merge,若没有冲突,进行下一步的push;若合并后有冲突,会报conflict错误,找到本地冲突的文件,进行修改,修改完成,继续 git add . -> git commit -am ‘merge from develop’ -> git pull -> git push
从develop合并到master
1、git checkout develop//切换到被合并分支
2、git pull//拉取被合并分支的最新代码
3、git checkout master//切换到主分支
4、git pull//拉取主分支的最新代码
5、git merge develop//将被合并分支 合并到 主分支
// 以上会将被合并分支 合并到 主分支之后,代码自动add和commit
6、查看有没有冲突,解决冲突
7、若有冲突并且解决之后,git add . -> git commit -am ‘merge from develop’, 若没有冲突,这步省略
8、git pull
9、git push
10、打tag
1)查看本地分支:
dahaideMBP:zhuanle-android dahai$ git branch
2.0.0
* master // 带*号的显示的是当前使用的分支
2)拉最新代码
dahaideMBP:zhuanle-android dahai$ git pull
Already up-to-date.
3)打tag
dahaideMBP:zhuanle-android dahai$ git tag release-2.0.2 -m '2.0.2 release tag'
4)把tag push 到服务器上
dahaideMBP:zhuanle-android dahai$ git push --tags
5)查看tag
git tag —list
11、拉取服务器最新版本库
git fetch //就能获取到服务版本库、分支
一旦远程主机的版本库有了更新(Git术语叫做commit),需要将这些更新取回本地,这时就要用到git fetch命令。
$ git fetch <远程主机名>
上面命令将某个远程主机的更新,全部取回本地。
默认情况下,git fetch取回所有分支(branch)的更新。如果只想取回特定分支的更新,可以指定分支名。
$ git fetch <远程主机名> <分支名>
比如,取回origin主机的master分支。
$ git fetch origin master
所取回的更新,在本地主机上要用”远程主机名/分支名”的形式读取。比如origin主机的master,就要用origin/master读取。