git 工作流程
设置用户信息
1
2
3
4
5
6
7
8
9
10[root@dev ~]# git config --global user.name "smallasa"
[root@dev ~]# git config --global user.email "smallasa@sina.com"
[root@dev ~]# git config --global push.default simple
[root@dev ~]# git config --global http.postBuffer 24288000
[root@dev ~]# git config --list
user.email=smallasa@sina.com
user.name=smallasa
push.default=simple
http.postbuffer=24288000克隆版本库
1
2
3
4
5
6
7
8
9
10[root@dev ~]# git clone http://github.com/smallasa/yaya.git
Cloning into 'yaya'...
Username for 'http://github.com': smallasa
Password for 'http://smallasa@github.com':
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
或者:
[root@dev ~]# git clone http://{USER}:{PASSWD}@github.com/smallasa/yaya.git查看当前分支
1
2
3
4
5
6
7
8
9
10
11
12
13[root@dev ~]# cd yaya/
//查看本地分支
[root@dev yaya]# git branch
* master
//查看远程分支
[root@dev yaya]# git branch -a
* master
remotes/origin/HEAD -> origin/master
remotes/origin/master
补充: 删除分支
[root@dev yaya]# git push origin --delete dev
[root@dev yaya]# git push origin :release创建分支
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19方法一:
[root@dev yaya]# git branch release
[root@dev yaya]# git branch
* master
release
[root@dev yaya]# git checkout release
Switched to branch 'release'
[root@dev yaya]# git branch
master
* release
方法二:
[root@dev yaya]# git checkout -b dev
Switched to a new branch 'dev'
[root@dev yaya]# git branch
* dev
master
release将分支推送到远端仓库上
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21[root@dev yaya]# git branch -a
dev
* master
release
remotes/origin/HEAD -> origin/master
remotes/origin/master
[root@dev yaya]# git push origin release
Username for 'http://github.com': smallasa
Password for 'http://smallasa@github.com':
Total 0 (delta 0), reused 0 (delta 0)
To http://github.com/smallasa/yaya.git
* [new branch] release -> release
[root@dev yaya]# git branch -a
dev
* master
release
remotes/origin/HEAD -> origin/master
remotes/origin/master
remotes/origin/release在release分支提交一个新文件
1
2
3
4
5
6
7
8
9
10
11[root@dev yaya]# git checkout release
[root@dev yaya]# echo '第一次发布版本' |tee -a a.txt
[root@dev yaya]# git add a.txt
[root@dev yaya]# git commit -m "add a.txt"
[root@dev yaya]# git log -1
commit 88d1fce9a2ce84f8fc3dce9223b81b2858d564f8
Author: smallasa <smallasa@sina.com>
Date: Mon Sep 11 09:02:52 2017 +0800
第一次发布版本对提交的内容打标签
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[root@dev yaya]# git tag -a v1.0 -m "v1.0版本发布"
[root@dev yaya]# git tag
v1.0
[root@dev yaya]# git show v1.0
tag v1.0
Tagger: smallasa <smallasa@sina.com>
Date: Mon Sep 11 09:03:55 2017 +0800
v1.0版本发布
commit 88d1fce9a2ce84f8fc3dce9223b81b2858d564f8
Author: smallasa <smallasa@sina.com>
Date: Mon Sep 11 09:02:52 2017 +0800
第一次发布版本
diff --git a/a.txt b/a.txt
new file mode 100644
index 0000000..a12bebd
--- /dev/null
+++ b/a.txt
@@ -0,0 +1 @@
+第一次发布版本
[root@dev yaya]# git push origin v1.0
Counting objects: 5, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (4/4), 470 bytes | 0 bytes/s, done.
Total 4 (delta 0), reused 0 (delta 0)
To http://smallasa:smallasa123@github.com/smallasa/yaya.git
* [new tag] v1.0 -> v1.0
补充:
[root@dev yaya]# git push origin v1.0 //推送单个tag到远程分支
[root@dev yaya]# git push --tags //推送所有tag到远程分支
[root@dev yaya]# git push origin --delete tag v1.0 //删除远程分支上指定tag
或者:
[root@dev yaya]# git tag -d Remote_Systems_Operation
[root@dev yaya]# git push origin :refs/tags/Remote_Systems_Operation
[root@dev yaya]# echo '第二次发布版本'|tee -a a.txt
[root@dev yaya]# git add a.txt
[root@dev yaya]# git commit -m "第二次发布版本"
[root@dev yaya]# echo '第三次发布版本'|tee -a a.txt
[root@dev yaya]# git add a.txt
[root@dev yaya]# git commit -m "第三次发布版本"
[root@dev yaya]# git log
commit cf76593438f987e61bf6dc7cd390c33edbf30804
Author: smallasa <smallasa@sina.com>
Date: Mon Sep 11 09:11:16 2017 +0800
第三次发布版本
commit 3a2b63f0786a6d16bc4bc50af132186b2d4e3fb2
Author: smallasa <smallasa@sina.com>
Date: Mon Sep 11 09:10:47 2017 +0800
第二次发布版本
commit 88d1fce9a2ce84f8fc3dce9223b81b2858d564f8
Author: smallasa <smallasa@sina.com>
Date: Mon Sep 11 09:02:52 2017 +0800
第一次发布版本
commit 7e6aa66ceec96fed7ba4b4a5e9d7d302974a987d
Author: smallasa <smallasa@sina.com>
Date: Wed Aug 30 12:03:04 2017 +0800
Initial commit回退到指定tag
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[root@dev yaya]# git tag
v1.0
[root@dev yaya]# git show v1.0
tag v1.0
Tagger: smallasa <smallasa@sina.com>
Date: Mon Sep 11 09:03:55 2017 +0800
v1.0版本发布
commit 88d1fce9a2ce84f8fc3dce9223b81b2858d564f8
Author: smallasa <smallasa@sina.com>
Date: Mon Sep 11 09:02:52 2017 +0800
第一次发布版本
diff --git a/a.txt b/a.txt
new file mode 100644
index 0000000..a12bebd
--- /dev/null
+++ b/a.txt
@@ -0,0 +1 @@
+第一次发布版本
[root@dev yaya]# cat a.txt
第一次发布版本
第二次发布版本
第三次发布版本
[root@dev yaya]# git reset --hard 88d1fce9a2ce84f8fc3dce9223b81b2858d564f8
HEAD is now at 88d1fce 第一次发布版本
[root@dev yaya]# cat a.txt
第一次发布版本
注意:
1.回退标签后,要基于回退当前目录创建一个新的分支:
[root@dev yaya]# git checkout -b bugfix
[root@dev yaya]# git branch
* bugfix
master
release
2.切换回原分支(此时还是回退tag位置):
//切换回原分支,并查看当前提交日志
[root@dev yaya]# git checkout release
Switched to branch 'release'
[root@dev yaya]# git log
commit 88d1fce9a2ce84f8fc3dce9223b81b2858d564f8
Author: smallasa <smallasa@sina.com>
Date: Mon Sep 11 09:02:52 2017 +0800
第一次发布版本
commit 7e6aa66ceec96fed7ba4b4a5e9d7d302974a987d
Author: smallasa <smallasa@sina.com>
Date: Wed Aug 30 12:03:04 2017 +0800
Initial commit
//回退到第三次提交位置
[root@dev yaya]# git reflog
88d1fce HEAD@{0}: checkout: moving from bugfix to release
88d1fce HEAD@{1}: checkout: moving from release to bugfix
88d1fce HEAD@{2}: reset: moving to 88d1fce9a2ce84f8fc3dce9223b81b2858d564f8
cf76593 HEAD@{3}: commit: 第三次发布版本
3a2b63f HEAD@{4}: commit: 第二次发布版本
88d1fce HEAD@{5}: commit: 第一次发布版本
7e6aa66 HEAD@{6}: checkout: moving from master to release
7e6aa66 HEAD@{7}: clone: from http://github.com/smallasa/yaya.git
[root@dev yaya]# git reset --hard cf76593
HEAD is now at cf76593 第三次发布版本
[root@dev yaya]# cat a.txt
第一次发布版本
第二次发布版本
第三次发布版本修复bug,并合并
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//切换到bugfix分支,修改bug
[root@dev yaya]# git checkout bugfix
[root@dev yaya]# echo '修复Bug' |tee -a a.txt
[root@dev yaya]# git add a.txt
[root@dev yaya]# git commit -m "修复Bug"
[root@dev yaya]# git tag v2.0
[root@dev yaya]# git tag
v1.0
v2.0
//合并到release分支:
[root@dev yaya]# git checkout release
[root@dev yaya]# cat a.txt
第一次发布版本
第二次发布版本
第三次发布版本
[root@dev yaya]# git merge bugfix
Auto-merging a.txt
CONFLICT (content): Merge conflict in a.txt
Automatic merge failed; fix conflicts and then commit the result.
[root@dev yaya]# cat a.txt
第一次发布版本
<<<<<<< HEAD
第二次发布版本
第三次发布版本
=======
修复Bug
>>>>>>> bugfix
[root@dev yaya]# vim a.txt
第一次发布版本
修复Bug
第二次发布版本
第三次发布版本
[root@dev yaya]# git add a.txt
[root@dev yaya]# git commit -m "修复bug"
[release 1adfe0e] 修复bug
[root@dev yaya]# git push origin --tags