常用命令總覽
$ 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"
創(chuàng)建倉庫
git init
-
遠(yuǎn)程倉庫
-
git remote -v
顯示關(guān)聯(lián)的遠(yuǎn)程倉庫 -
git remote add origin git@github.com:classQ/test.git
關(guān)聯(lián)遠(yuǎn)程倉庫 -
git clone git@github.com:classQ/test.git
克隆遠(yuǎn)程倉庫
-
-
遠(yuǎn)程協(xié)作
-
git pull origin master
獲取遠(yuǎn)程倉庫代碼 -
git push orgin master
推送到遠(yuǎn)程倉庫(為了避免沖突等脂,push前先pull)
-
-
分支
-
git branch -b a
創(chuàng)建分支a -
git checkout a
切換到分支a -
git checkout -b a
創(chuàng)建并切換分支a -
git branch -d a
刪除分支a -
git merge a
合并分支
-
-
tag
我們?cè)诳蛻舳碎_發(fā)的時(shí)候經(jīng)常有版本的概念姻成,比如v1.0、v1.1之類的乒躺,不同的版本肯定對(duì)應(yīng)不同的代碼,所以我一般要給我們的代碼加上標(biāo)簽低缩,這樣假設(shè)v1.1版本出了一個(gè)新bug嘉冒,但是又不曉得v1.0是不是有這個(gè)bug,有了標(biāo)簽就可以順利切換到v1.0的代碼咆繁,重新打個(gè)包測(cè)試了讳推。
-
git tag
顯示當(dāng)前創(chuàng)建了哪些tag -
git tag v1.0
創(chuàng)建tag v1.0
-
遠(yuǎn)程倉庫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的內(nèi)容)添加到github中去