Git 命令大全
最近常用到的一些命令,记录下来
git
显示命令和帮助
git help <command>
打开对应命令的帮助信息
git status
查看工作区状态
git diff
查看文件的修改内容
git add <file>
缓存修改
git add .
缓存所有修改,同 git add -all (-a)
git commit -m "<comment>"
提交修改并添加comment
git push
将本地分支的更新,推送到远程主机
git pull
拉取远程代码到本地
git branch
查看当前分支
git branch -a
查看所有分支(local和remote)
git branch <newBranch>
切换新的分支 newBranch
git checkout <branch>
切换到branch分支
git checkout -b <newBranch>
创建并切换到新的分支newBranch
git branch -d <branch_name>
删除本地分支
git push origin -d <branch_name>
,git push origin --delete <branchName>
,或者 git push origin :<branch_name>
删除远程分支
git checkout --<file>
撤销未缓存的文件修改
git rm --cached <file>
,git rm -r --cached <files>
删除新加入ignore的文件
git reset HEAD <file>
撤销已缓存的文件修改
git reset HEAD~1 --hard
通过reset HEAD的方式来撤销一次提交(~2 两次)
git push <remote> <branch> --force (-f)
推送到服务器
git rm <file>
删除文件,之后需要commit
git remote set-url origin git@github.com:<Username>/<Project>.git
更换远程仓库地址(ssh)
git config --global alias.acm '!git commit -a -m'
可以自定义acm命令,实现add + commit -m的功能,之后就可以使用git acm
了
使用git在本地创建一个项目的过程
1
2
3
4
5
6
7
8
$ makdir ~/hello-world //创建一个项目hello-world
$ cd ~/hello-world //打开这个项目
$ git init //初始化
$ touch README
$ git add README //更新README文件
$ git commit -m 'first commit' //提交更新,并注释信息“first commit”
$ git remote add origin git@github.com:defnngj/hello-world.git //连接远程github项目
$ git push -u origin master //将本地项目更新到github项目上去
Markdown Learning
First - Headings
There are two ways to generate headings: # and ==
A # and a blank after it will generate a first level heading as this section title. An = (can be more) or a - will also generate a first level heading.
## for second level heading and ### for third level heading and so on.
Second - Font
This is a itallic (using ** ) text (using _ _ ). And this is a bold (using ** ** ) font (using _ _ _ _ )
Third - Language
Markdown supports 中文, 日本語の, 한국어, русский, El español, Português, svenska, In Italiano …
Fourth - List
I’d like to see a unordered list(using *, + or - ).
- Hello
- こんにちは
- 你好
and a ordered list
- Throw away your mobile phone
- Talk to someone
- Be happy
Fifth - HTML & Table
I can create a table using:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<table>
<thead>
<tr>
<th>Head</th>
<th>Head2</th>
<th>Head3</th>
<th>Head4</th>
</tr>
</thead>
<tbody>
<tr>
<td>Foo</td>
<td>Foo2</td>
<td>Foo3</td>
<td>Foo4</td>
</tr>
<tr>
<td>Coo</td>
<td>Coo2</td>
<td>Coo3</td>
<td>Coo4</td>
</tr>
</tbody>
</table>
And it shows like this:
Head | Head2 | Head3 | Head4 |
---|---|---|---|
Foo | Foo2 | Foo3 | Foo4 |
Coo | Coo2 | Coo3 | Coo4 |
Or using:
1
2
3
4
5
| Tables | Are | Cool |
| ------------- |:-------------:| -----:|
| col 3 is | right-aligned | $1600 |
| col 2 is | centered | $12 |
| zebra stripes | are neat | $1 |
which shows like
Tables | Are | Cool |
---|---|---|
col 3 is | right-aligned | $1600 |
col 2 is | centered | $12 |
zebra stripes | are neat | $1 |
Sixth - JS code
``` ``` is use for presenting codes
1
2
console.log("Hello there!");
console.info("How good the weather it is!");
I also can use <code> </code>:
console.log("
code
");
again
Or ` ` for inline code: alert("inline code")
Seventh - Split lines
*** or — at new lines can generate split lines.
line1
line2
line3
Eighth - Image & Link
Currently markdown can’t control the width and height of an image.
This is a link to xkcd.com(a funny website. I am sure you will love it).