Git提交代码的处理流程(转)

简介: Jerry 工作在wchar_support分支。他改变了名称的功能和测试后,他提交他的变化。 [jerry@CentOS src]$ git branch master * wchar_support [jerry@CentOS src]$ git diff 上面的命令产生以下结果 diff --git a/src/string_operations.

Jerry 工作在wchar_support分支。他改变了名称的功能和测试后,他提交他的变化。

[jerry@CentOS src]$ git branch
 master
* wchar_support
[jerry@CentOS src]$ git diff

上面的命令产生以下结果

diff --git a/src/string_operations.c b/src/string_operations.c
index 8fb4b00..01ff4e0 100644
--- a/src/string_operations.c
+++ b/src/string_operations.c
@@ -1,7 +1,7 @@
#include <stdio.h>
#include <wchar.h>
-size_t w_strlen(const wchar_t *s)
+size_t my_wstrlen(const wchar_t *s)
{
const wchar_t *p = s;

验证代码后,他提交了他的变化。

[jerry@CentOS src]$ git status -s
M string_operations.c

[jerry@CentOS src]$ git add string_operations.c

[jerry@CentOS src]$ git commit -m 'Changed function name'
[wchar_support 3789fe8] Changed function name
1 files changed, 1 insertions(+), 1 deletions(-)

[jerry@CentOS src]$ git push origin wchar_support

上面的命令会产生以下结果。

Counting objects: 7, done.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 409 bytes, done.
Total 4 (delta 1), reused 0 (delta 0)
To gituser@git.server.com:project.git
64192f9..3789fe8 wchar_support -> wchar_support

在主分支进行更改

同时在主分支Tom 也改变了名称相同的功能,并将其更改到主分支。

[tom@CentOS src]$ git branch
* master
[tom@CentOS src]$ git diff

上面的命令会产生以下结果。

diff --git a/src/string_operations.c b/src/string_operations.c
index 8fb4b00..52bec84 100644
--- a/src/string_operations.c
+++ b/src/string_operations.c
@@ -1,7 +1,8 @@
#include <stdio.h>
#include <wchar.h>
-size_t w_strlen(const wchar_t *s)
+/* wide character strlen fucntion */
+size_t my_wc_strlen(const wchar_t *s)
{
const wchar_t *p = s;

验证差异后,他提交了他的变化。

[tom@CentOS src]$ git status -s
M string_operations.c

[tom@CentOS src]$ git add string_operations.c

[tom@CentOS src]$ git commit -m 'Changed function name from w_strlen to my_wc_strlen'
[master ad4b530] Changed function name from w_strlen to my_wc_strlen
1 files changed, 2 insertions(+), 1 deletions(-)

[tom@CentOS src]$ git push origin master

上面的命令会产生以下结果。

Counting objects: 7, done.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 470 bytes, done.
Total 4 (delta 1), reused 0 (delta 0)
To gituser@git.server.com:project.git
64192f9..ad4b530 master -> master

strchr 函数在分支Jerry 实现 wchar_support宽字符字符串。经过测试,他提交和推送其变化 wchar_support 分支。

[jerry@CentOS src]$ git branch
master
* wchar_support
[jerry@CentOS src]$ git diff

上面的命令会产生以下结果。

diff --git a/src/string_operations.c b/src/string_operations.c
index 01ff4e0..163a779 100644
--- a/src/string_operations.c
+++ b/src/string_operations.c
@@ -1,6 +1,16 @@
#include <stdio.h>
#include <wchar.h>
+wchar_t *my_wstrchr(wchar_t *ws, wchar_t wc)
+{
+
while (*ws) {
+
if (*ws == wc)
+
return ws;
+
++ws;
+ }
+ return NULL;
+}
+
size_t my_wstrlen(const wchar_t *s)
{
const wchar_t *p = s;

验证变化后,他提交他的变化。

[jerry@CentOS src]$ git status -s
M string_operations.c

[jerry@CentOS src]$ git add string_operations.c

[jerry@CentOS src]$ git commit -m 'Addded strchr function for wide character string'
[wchar_support 9d201a9] Addded strchr function for wide character string
1 files changed, 10 insertions(+), 0 deletions(-)

[jerry@CentOS src]$ git push origin wchar_support

上面的命令会产生以下结果。

Counting objects: 7, done.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 516 bytes, done.
Total 4 (delta 1), reused 0 (delta 0)
To gituser@git.server.com:project.git
3789fe8..9d201a9 wchar_support -> wchar_support

对付冲突

Tom想看,Jerry 在他的私人分支做什么?这就是为什么他试图从wchar_support分支把最新的修改,但Git 放弃操作在得到错误消息后。

[tom@CentOS src]$ git pull origin wchar_support

上面的命令会产生以下结果。

remote: Counting objects: 11, done.
63Git Tutorials
remote: Compressing objects: 100% (8/8), done.
remote: Total 8 (delta 2), reused 0 (delta 0)
Unpacking objects: 100% (8/8), done.
From git.server.com:project
* branch
wchar_support -> FETCH_HEAD
Auto-merging src/string_operations.c
CONFLICT (content): Merge conflict in src/string_operations.c
Automatic merge failed; fix conflicts and then commit the result.

解决冲突

从错误消息很显然知道,是有冲突的在src/string_operations.c。他运行 git diff 命令查看进一步的细节。

[tom@CentOS src]$ git diff

上面的命令会产生以下结果。

diff --cc src/string_operations.c
index 52bec84,163a779..0000000
--- a/src/string_operations.c
+++ b/src/string_operations.c
@@@ -1,8 -1,17 +1,22 @@@
#include <stdio.h>
#include <wchar.h>
++<<<<<<< HEAD
+/* wide character strlen fucntion */
+size_t my_wc_strlen(const wchar_t *s)
++=======
+ wchar_t *my_wstrchr(wchar_t *ws, wchar_t wc)
+{
+
+
while (*ws) {
if (*ws == wc)
+
return ws;
+
++ws;
+ }
+ return NULL;
+}
+
+ size_t my_wstrlen(const wchar_t *s)
++>>>>>>>9d201a9c61bc4713f4095175f8954b642dae8f86
{
const wchar_t *p = s;

由于Tom 和Jerry 在相同的功能更改的名称,Git不知道如何去做,因此这就是为什么它要求用户手动解决冲突。

Tom 决定保用 Jerry 建议的函数名,但他使用原来注释,因为这是他加入的。删除冲突标记混帐后差异会看起来像这样。

[tom@CentOS src]$ git diff

上面的命令会产生以下结果。

diff --cc src/string_operations.c
diff --cc src/string_operations.c
index 52bec84,163a779..0000000
--- a/src/string_operations.c
+++ b/src/string_operations.c
@@@ -1,8 -1,17 +1,18 @@@
#include <stdio.h>
#include <wchar.h>
+ wchar_t *my_wstrchr(wchar_t *ws, wchar_t wc)
+{
+
while (*ws) {
+
if (*ws == wc)
+
return ws;
+
++ws;
+ }
+ return NULL;
+}
+
+/* wide character strlen fucntion */
- size_t my_wc_strlen(const wchar_t *s)
+ size_t my_wstrlen(const wchar_t *s)
{
const wchar_t *p = s;

Tom 修改过的文件,他先提交这些更改后,他就可以推送了。

[tom@CentOS src]$ git commit -a -m 'Resolved conflict'
[master 6b1ac36] Resolved conflict

[tom@CentOS src]$ git push origin wchar_support.

Tom 已经解决冲突,现在推送操作将成功。


http://www.yiibai.com/git/git_handling_conflicts.html


相关文章
|
24天前
|
安全 开发工具 数据安全/隐私保护
《Git 简易速速上手小册》第8章:保护你的代码(2024 最新版)
《Git 简易速速上手小册》第8章:保护你的代码(2024 最新版)
31 1
|
14天前
|
存储 开发工具 git
|
22天前
|
敏捷开发 测试技术 持续交付
云效产品使用常见问题之直接git clone 输入账密可以拉代码,但是云效平台上不行如何解决
云效作为一款全面覆盖研发全生命周期管理的云端效能平台,致力于帮助企业实现高效协同、敏捷研发和持续交付。本合集收集整理了用户在使用云效过程中遇到的常见问题,问题涉及项目创建与管理、需求规划与迭代、代码托管与版本控制、自动化测试、持续集成与发布等方面。
|
24天前
|
Shell 测试技术 开发工具
《Git 简易速速上手小册》第9章:Git 工作流程定制(2024 最新版)
《Git 简易速速上手小册》第9章:Git 工作流程定制(2024 最新版)
26 1
|
24天前
|
开发工具 git
git 拉取代码仓库代码报错(合并错误 refusing to merge unrelated histories)
git 拉取代码仓库代码报错(合并错误 refusing to merge unrelated histories)
26 0
|
28天前
|
数据可视化 开发工具 git
Git代码版本管理入门
Git代码版本管理入门
|
28天前
|
Shell 网络安全 开发工具
还不会 Git?最详细教你学会 Git + TortoiseGit 安装使用及提交代码!
还不会 Git?最详细教你学会 Git + TortoiseGit 安装使用及提交代码!
|
1月前
|
开发工具 git
对于github不同的分支main或者master,git拉取代码的时候怎么拉取不同分支的代码
对于github不同的分支main或者master,git拉取代码的时候怎么拉取不同分支的代码
24 1
|
2月前
|
开发工具 C语言 数据安全/隐私保护
git提交代码到远端仓库的方法详解
git提交代码到远端仓库的方法详解
|
2月前
|
程序员 开发工具 git
【程序员英语 代码提交】C++工程师的代码提交艺术:git commit 时 精确表达与最佳实践
【程序员英语 代码提交】C++工程师的代码提交艺术:git commit 时 精确表达与最佳实践
120 1