-
Notifications
You must be signed in to change notification settings - Fork 0
/
git_help.txt
168 lines (141 loc) · 7.16 KB
/
git_help.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
usage: git [--version] [--exec-path[=GIT_EXEC_PATH]] [--html-path]
[-p|--paginate|--no-pager] [--no-replace-objects]
[--bare] [--git-dir=GIT_DIR] [--work-tree=GIT_WORK_TREE]
[-c name=value] [--help]
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
See 'git help COMMAND' for more information on a specific command.
##=============================================================================
## 常用命令BEGIN
##=============================================================================
##==== Test everything out. ====
$ ssh -T git@github.com
# Type “yes”.
##==== Set Up Your Info. ====
$ git config --global user.name "Firstname Lastname"
$ git config --global user.email "your_email@youremail.com"
# git config core.editor vim
# git config core.paper "less -N"
# git config color.diff true
# git config alias.co checkout
##==== Create a README for your repo. ====
$ mkdir ~/Hello-World
$ cd ~/Hello-World
$ git init
$ touch README
$ git add README
$ git commit -m "first commit"
$ git remote add origin git@github.com:username/Hello-World.git
$ git push -u origin master
##Existing Git Repo?
$ cd existing_git_repo
$ git remote add origin git@github.com:username/Hello-World.git
$ git push -u origin master
##Create a branch
$ git branch gh-pages
$ git push -u origin gh-pages
##==== Commonly used git commands. ====
git init [-q | --quiet] [--bare] [--template=<template_directory>] [--shared[=<permissions>]] [directory]
#= eg: "git init"
git clone [--template=<template_directory>]
[-l] [-s] [--no-hardlinks] [-q] [-n] [--bare] [--mirror]
[-o <name>] [-b <name>] [-u <upload-pack>] [--reference <repository>]
[--depth <depth>] [--recursive] [--] <repository> [<directory>]
#= eg: "git clone git@github.com:mismo/mismo.github.com.git e:\opensrc\zhi\mismo.github.com"
git add [-n] [-v] [--force | -f] [--interactive | -i] [--patch | -p]
[--edit | -e] [--all | [--update | -u]] [--intent-to-add | -N]
[--refresh] [--ignore-errors] [--ignore-missing] [--]
[<filepattern>…]
#= eg: "git add -A", "git add Documentation/\*.txt", "git add git-*.sh"
git rm [-f | --force] [-n] [-r] [--cached] [--ignore-unmatch] [--quiet] [--] <file>…
#= eg: "git rm -r tmp"
git commit [-a | --interactive] [-s] [-v] [-u<mode>] [--amend] [--dry-run]
[(-c | -C) <commit>] [-F <file> | -m <msg>] [--reset-author]
[--allow-empty] [--allow-empty-message] [--no-verify] [-e] [--author=<author>]
[--date=<date>] [--cleanup=<mode>] [--status | --no-status] [--]
[[-i | -o ]<file>…]
#= eg: "git commit -m 'commit msg'", "git commit -a"
# Exit commit message editor(VIM): Esc, :w = save; :wq = save and quit; :x = save and quit; :q = quit,but failed if unsaved :q! = quit.
git push [--all | --mirror | --tags] [-n | --dry-run] [--receive-pack=<git-receive-pack>]
[--repo=<repository>] [-f | --force] [-v | --verbose] [-u | --set-upstream]
[<repository> [<refspec>…]]
#= eg: "git push -u origin master", "git push origin gh-pages"
git pull [options] [<repository> [<refspec>…]]
#= eg: "git pull origin"
git checkout [-q] [-f] [-m] [<branch>]
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 --patch [<tree-ish>] [--] [<paths>…]
#= eg: "git checkout master", "git checkout gh-pages"
git remote [-v | --verbose]
git remote add [-t <branch>] [-m <master>] [-f] [--tags|--no-tags] [--mirror] <name> <url>
git remote rename <old> <new>
git remote rm <name>
git remote set-head <name> (-a | -d | <branch>)
git remote set-branches <name> [--add] <branch>…
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]…
#= eg: "git remote add origin git@github.com:username/Hello-World.git"
git fetch [<options>] [<repository> [<refspec>…]]
git fetch [<options>] <group>
git fetch --multiple [<options>] [<repository> | <group>]…
git fetch --all [<options>]
#= eg: "git fetch", "git fetch origin"
git branch [--color[=<when>] | --no-color] [-r | -a]
[-v [--abbrev=<length> | --no-abbrev]]
[(--merged | --no-merged | --contains) [<commit>]]
git branch [--set-upstream | --track | --no-track] [-l] [-f] <branchname> [<start-point>]
git branch (-m | -M) [<oldbranch>] <newbranch>
git branch (-d | -D) [-r] <branchname>…
git branch -a 查看所有分支。
git branch new_branch 创建新的分支。
git branch -d branch_name 删除分支。
git checkout branch_name 切换当前分支。-f参数可以覆盖未提交内容。
git diff tag 比较tag和HEAD之间的不同。
git diff tag file 比较一个文件在两者之间的不同。
git diff tag1..tag2 比较两个tag之间的不同。
git diff SHA11..SHA12 比较两个提交之间的不同。
git diff tag1 tag2 file or
git diff tag1:file tag2:file 比较一个文件在两个tag之间的不同。
git reset HEAD^ or
git reset HEAD~1 撤销最后一次提交。
git reset --hard HEAD^ 撤销最后一次提交并清除本地修改。
git reset SHA1 回到SHA1对应的提交状态。
git ls-files -m 显示修改过的文件。
git ls-files 显示所有仓库中的文件。
git log file 查看一个文件的改动。
git log -p 查看日志和改动。
git log tag1..tag2 查看两个tag之间的日志。
git log -p tag1..tag2 file 查看一个文件在两个tag之间的不同。
git log tag.. 查看tag和HEAD之间的不同。
git clean -dxf 用于清除未跟踪文件。
git clean -dnf 可以显示需要删除的文件,但不包括被.gitignore忽略的。
git reset --hard HEAD 用于清除跟踪文件的修改。
##=============================================================================
## 常用命令END
##=============================================================================