合并两个分支
Jerry实现了一个返回宽字符串的字符串长度的函数。新的代码将显示如下-
[jerry@CentOS src]$ git branch
master
* wchar_support
[jerry@CentOS src]$ pwd
/home/jerry/jerry_repo/project/src
[jerry@CentOS src]$ git diff
上面的命令产生以下结果-
t a/src/string_operations.c b/src/string_operations.c
index 8ab7f42..8fb4b00 100644
--- a/src/string_operations.c
+++ b/src/string_operations.c
@@ -1,4 +1,14 @@
#include <stdio.h>
+#include <wchar.h>
+
+size_t w_strlen(const wchar_t *s)
+
{
+
const wchar_t *p = s;
+
+
while (*p)
+ ++p;
+ return (p - s);
+
}
测试后,他提交并将更改推送到新分支。
[jerry@CentOS src]$ git status -s
M string_operations.c
?? string_operations
[jerry@CentOS src]$ git add string_operations.c
[jerry@CentOS src]$ git commit -m 'Added w_strlen function to return string lenght of wchar_t
string'
[wchar_support 64192f9] Added w_strlen function to return string lenght of wchar_t string
1 files changed, 10 insertions(+), 0 deletions(-)
请注意,Jerry将这些更改推送到新分支,这就是为什么他使用分支名称wchar_support而不是master分支的原因。
[jerry@CentOS src]$ git push origin wchar_support
上面的命令将产生以下结果。
Counting objects: 7, done.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 507 bytes, done.
Total 4 (delta 1), reused 0 (delta 0)
To gituser@git.server.com:project.git
* [new branch]
wchar_support -> wchar_support
提交更改后,新分支将如下所示:
Tom对Jerry在他的私有分支中正在做什么感到好奇,他检查wchar_support分支中的日志。
[tom@CentOS src]$ pwd
/home/tom/top_repo/project/src
[tom@CentOS src]$ git log origin/wchar_support -2
上面的命令将产生以下结果。
commit 64192f91d7cc2bcdf3bf946dd33ece63b74184a3
Author: Jerry Mouse <jerry@cainiaoya.com>
Date: Wed Sep 11 16:10:06 2013 +0530
Added w_strlen function to return string lenght of wchar_t string
commit 577647211ed44fe2ae479427a0668a4f12ed71a1
Author: Tom Cat <tom@cainiaoya.com>
Date: Wed Sep 11 10:21:20 2013 +0530
Removed executable binary
通过查看提交消息,Tom意识到Jerry为宽字符实现了strlen函数,并且他希望在master分支中具有相同的功能。他决定不重新实现,而是决定通过git merge
命令将其分支与master分支合并来采用Jerry的代码。
[tom@CentOS project]$ git branch
* master
[tom@CentOS project]$ pwd
/home/tom/top_repo/project
[tom@CentOS project]$ git merge origin/wchar_support
Updating 5776472..64192f9
Fast-forward
src/string_operations.c | 10 ++++++++++
1 files changed, 10 insertions(+), 0 deletions(-)
合并操作后,master分支将显示如下-
现在,分支wchar_support已与master分支合并。我们可以通过查看提交消息或查看对string_operation.c文件所做的修改来验证它。
[tom@CentOS project]$ cd src/
[tom@CentOS src]$ git log -1
commit 64192f91d7cc2bcdf3bf946dd33ece63b74184a3
Author: Jerry Mouse
Date: Wed Sep 11 16:10:06 2013 +0530
Added w_strlen function to return string lenght of wchar_t string
[tom@CentOS src]$ head -12 string_operations.c
上面的命令将产生以下结果。
#include <stdio.h>
#include <wchar.h>
size_t w_strlen(const wchar_t *s)
{
const wchar_t *p = s;
while (*p)
++p;
return (p - s);
}
测试之后,他将代码更改推送到master分支。
[tom@CentOS src]$ git push origin master
Total 0 (delta 0), reused 0 (delta 0)
To gituser@git.server.com:project.git
5776472..64192f9 master −> master