常用命令总览
$ 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 Reapply commits on top of another base tip
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.
常用命令
-
初始化配置
git config --global user.name "Your Name"
git config --global user.email "email@example.com"
-
创建仓库
git init
-
远程仓库
-
git remote -v
显示关联的远程仓库 -
git remote add origin git@github.com:classQ/test.git
关联远程仓库 -
git clone git@github.com:classQ/test.git
克隆远程仓库
-
-
远程协作
-
git pull origin master
获取远程仓库代码 -
git push orgin master
推送到远程仓库(为了避免冲突,push前先pull)
-
-
分支
-
git branch -b a
创建分支a -
git checkout a
切换到分支a -
git checkout -b a
创建并切换分支a -
git branch -d a
删除分支a -
git merge a
合并分支
-
-
tag
我们在客户端开发的时候经常有版本的概念,比如v1.0、v1.1之类的,不同的版本肯定对应不同的代码,所以我一般要给我们的代码加上标签,这样假设v1.1版本出了一个新bug,但是又不晓得v1.0是不是有这个bug,有了标签就可以顺利切换到v1.0的代码,重新打个包测试了。
-
git tag
显示当前创建了哪些tag -
git tag v1.0
创建tag v1.0
-
远程仓库github
添加SSH key到github中
- 生成rsa公钥与私钥("C:\Users\Administrator.ssh[id_rsa.pub|id_rsa]")
$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/Administrator/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/Administrator/.ssh/id_rsa.
Your public key has been saved in /c/Users/Administrator/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:J4Up2SmaEeYElOex+O0s+cLmtb/ArfLnYT2mvm5mCOI Administrator@LS--20160418PSW
The key's randomart image is:
+---[RSA 2048]----+
| .oo+ |
| .+o. o + |
| +oo+ = . |
| . o+ o . |
| .o. S . |
| . o... + |
| . o =+.+ + |
| E B.+==+ . |
| o.*=XOo |
+----[SHA256]-----+
- 将公钥(id_rsa.pub的内容)添加到github中去
网友评论