Git Tutorials: Learn Version Control Step-by-Step
Dive into Git with our in-depth tutorials. From the fundamentals to advanced techniques, we'll guide you through the process of effectively using Git for version control. Build practical projects and master Git's powerful features.
Perform Changes in wchar_support
Branch
Tom is working on the wchar_support
branch. He makes changes to the function names and commits them after testing.
Command
[tom@CentOS src]$ git branch
master
* wchar_support
[tom@CentOS src]$ git diff
Output
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
-size_t w_strlen(const wchar_t *s)
+size_t my_wstrlen(const wchar_t *s)
After verifying the code, Tom commits and pushes his changes:
Command
[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'
[tom@CentOS src]$ git push origin wchar_support
Output
Counting objects: 7, done.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 409 bytes, done.
To gituser@git.server.com:project.git
64192f9..3789fe8 wchar_support -> wchar_support
Perform Changes in Master
Branch
Meanwhile, in the master branch, david also modifies the same function and commits his changes.
Command
[david@CentOS src]$ git branch
* master
[david@CentOS src]$ git diff
Output
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
-size_t w_strlen(const wchar_t *s)
+/* wide character strlen function */
+size_t my_wc_strlen(const wchar_t *s)
After testing, david commits and pushes his changes:
Command
[david@CentOS src]$ git commit -m 'Changed function name from w_strlen to my_wc_strlen'
[david@CentOS src]$ git push origin master
Output
Counting objects: 7, done.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 470 bytes, done.
To gituser@git.server.com:project.git
64192f9..ad4b530 master -> master
Tackle Conflicts
david attempts to pull the latest changes from the wchar_support
branch, but Git detects a conflict.
Command
[david@CentOS src]$ git pull origin wchar_support
Output
Auto-merging src/string_operations.c
CONFLICT (content): Merge conflict in src/string_operations.c
Resolve Conflicts
david inspects the conflict and decides to merge Tom's changes but keeps his own comment:
Command
[david@CentOS src]$ git diff
[david@CentOS src]$ git commit -a -m 'Resolved conflict'
[david@CentOS src]$ git pull origin wchar_support
Output
[master 6b1ac36] Resolved conflict
david has successfully resolved the conflict and pulled the latest changes.