概述

我们可以把 Git 分成两个部分,一个是远程仓库 Remote Repository,还有一个是本地环境 Development Environment

命令

git clone

git add

git commit -m ‘commit’

git push

git pull

拉取远程仓库的代码

git status

查看 Working Directory 和 Staging Area 中更改的文件

1
2
3
4
5
6
7
8
9
10
11
12
> git status
On branch pre
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)

modified: src/config.js

Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)

modified: src/main.js

git diff

查看 Working Directory 中更改的文件和内容

1
2
3
4
5
6
7
8
9
10
11
diff --git a/src/main.js b/src/main.js
index cd229cd..4a00e12 100644
--- a/src/main.js
+++ b/src/main.js
@@ -30,7 +30,7 @@ **********
*******
*******
-Vue.config.productionTip = false
+Vue.config.productionTip = false;
********
********

git diff –staged

查看 Staging Area 中更改的文件和内容

git diff^! / git diff

1
2
git diff 87a4ad48d55e5280aa608cd79e8bce5e13f318dc^!
git diff 8af2ff2a8f7c51e2e52402ecb7332aec39ed540e 87a4ad48d55e5280aa608cd79e8bce5e13f318dc
  • git diff^! 来比较这次 commit 和上一次提交的变动内容
  • git diff比较这两次 commit 之间的变动内容

git log

我们不仅可以看到所有提交及其哈希、作者和日期的列表,还可以看到本地存储库的状态以及有关远程分支的最新本地信息

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
commit 87a4ad48d55e5280aa608cd79e8bce5e13f318dc (HEAD -> master)
Author: {YOU} <{YOUR EMAIL}>
Date: Sun Jan 27 14:02:48 2019 +0100

Add text to Bob

commit 8af2ff2a8f7c51e2e52402ecb7332aec39ed540e (origin/master, origin/HEAD)
Author: {YOU} <{YOUR EMAIL}>
Date: Sun Jan 27 13:35:41 2019 +0100

Add Bob

commit 71a6a9b299b21e68f9b0c61247379432a0b6007c
Author: UnseenWizzard <nicola.riedmann@live.de>
Date: Fri Jan 25 20:06:57 2019 +0100

Add Alice

commit ddb869a0c154f6798f0caae567074aecdfa58c46
Author: Nico Riedmann <UnseenWizzard@users.noreply.github.com>
Date: Fri Jan 25 19:25:23 2019 +0100

Add Tutorial Text

Changes to the tutorial are all squashed into this commit on master, to keep the log free of clutter that distracts from the tutorial

See the tutorial_wip branch for the actual commit history

git branch

创建一个新的本地分支 demo

1
git branch demo

git checkout

切换本地分支

1
git checkout demo

git rebase

将原本的分叉提交变成一条直线,简化提交历史,看上去更直观。

git fetch

git fetch 相当于是从远程获取最新到本地,不会自动merge
git pull 相当于是从远程获取最新版本并merge到本地

git stash

缓存当前更改