Update activity in Git
Customize existing functions
Tom performs the simulation operation and sees a new file string.c. He wants to know who added this file to the repository and for what purpose, so he runs the git log command.
[tom @ CentOS ~] $ git clone gituser@git.server.com: project.git
This command will produce the following result:
Initialized empty Git repository in /home/tom/project/.git/
remote: Counting objects: 6, done.
remote: Compressing objects: 100% (4/4), done.
Receiving objects: 100% (6/6), 726 bytes, done.
remote: Total 6 (delta 0), reused 0 (delta 0)
The simulation operation will create a new folder inside the current working directory. He changed the directory to the newly created folder and ran the git log command.
[tom @ CentOS ~] $ cd project /
[tom @ CentOS project] $ git log
The above command will produce the following result:
commit d1e19d316224cddc437e3ed34ec3c931ad803958
Author: Jerry Mouse
Date: Wed Sep 11 08:05:26 2013 +0530
Changed return type of my_strlen to size_t
commit 19ae20683fc460db7d127cf201a1429523b0e319
Author: Tom Cat
Date: Wed Sep 11 07:32:56 2013 +0530
Initial commit
After observing the log, he noticed that the file string.c was added by Jerry to perform basic string operations. He wants to know about Jerry's code. So he opens string.c in the text editor and immediately finds a bug (error). In the function my_strlen, Jerry does not use a constant pointer. Therefore, he decided to edit Jerry's code. After editing, the code looks like this:
[tom @ CentOS project] $ git diff
The above command will produce the following result:
diff --git a / string.cb / string.c
index 7da2992.32489eb 100644
--- a / string.c
+++ b / string.c
@@ -1,8 +1,8 @@
#include
-size_t my_strlen (char * s)
+ size_t my_strlen (const char * s)
{
- char * p = s;
+ const char * p = s;
while (* p)
++ p;
}
After checking, he commits his changes.
[tom @ CentOS project] $ git status -s
M string.c
?? string
[tom @ CentOS project] $ git add string.c
[tom @ CentOS project] $ git commit -m 'Changed char pointer to const char pointer'
[master cea2c00] Changed char pointer to const char pointer
1 files changed, 2 insertions (+), 2 deletions (-)
[tom @ CentOS project] $ git log
The above command will produce the following result:
commit cea2c000f53ba99508c5959e3e12fff493b
Author: Tom Cat
Date: Wed Sep 11 08:32:07 2013 +0530
Changed char pointer to const char pointer
commit d1e19d316224cddc437e3ed34ec3c931ad803958
Author: Jerry Mouse
Date: Wed Sep 11 08:05:26 2013 +0530
Changed return type of my_strlen to size_t
commit 19ae20683fc460db7d127cf201a1429523b0e319
Author: Tom Cat
Date: Wed Sep 11 07:32:56 2013 +0530
Initial commit
Tom uses git push command to push his changes.
[tom @ CentOS project] $ git push origin master
The above command will produce the following result:
Counting objects: 5, done.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 336 bytes, done.
Total 3 (delta 1), reused 0 (delta 0)
To gituser@git.server.com: project.git
d1e19d3.cea2c00 master -> master
Add new functions
Meanwhile, Jerry decided to implement string compare function. So he edited string.c. After customization, the file looks like this:
[jerry @ CentOS project] $ git diff
The above command will produce the following result:
index 7da2992.bc864ed 100644
--- a / string.c
+++ b / string.c
30Git Tutorials
@@ -9,9 +9,20 @@ size_t my_strlen (char * s)
return (p -s);
}
+ char * my_strcpy (char * t, char * s)
+
{
+
char * p = t;
+
+ while (* t ++ = * s ++)
+;
+
+
return p;
+
}
+
int main (void)
{
int i;
+
char p1 [32];
char * s [] =
{
"Git tutorials",
"Tutorials Point"
@@ -20.5 +31,7 @@ int main (void)
for (i = 0; i <2; ++ i)
printf ("string lenght of% s =% lun", s [i], my_strlen (s [i]));
+
printf ("% sn", my_strcpy (p1, "Hello, World !!!"));
+
return 0;
}
}
After checking, he is ready to push this change.
[jerry @ CentOS project] $ git status -s
M string.c
?? string
[jerry @ CentOS project] $ git add string.c
[jerry @ CentOS project] $ git commit -m "Added my_strcpy function"
[master e944e5a] Added my_strcpy function
1 files changed, 13 insertions (+), 0 deletions (-)
Before performing the push operation, he modifies the commit by observing the log messages.
[jerry @ CentOS project] $ git log
The above command will produce the following result:
commit e944e5aab74b26e7447d3281b225309e4e59efcd
Author: Jerry Mouse
Date: Wed Sep 11 08:41:42 2013 +0530
Added my_strcpy function
commit d1e19d316224cddc437e3ed34ec3c931ad803958
Author: Jerry Mouse
Date: Wed Sep 11 08:05:26 2013 +0530
Changed return type of my_strlen to size_t
commit 19ae20683fc460db7d127cf201a1429523b0e319
Author: Tom Cat
Date: Wed Sep 11 07:32:56 2013 +0530
Initial commit
Jerry is happy with these changes and he wants to push those changes.
[jerry @ CentOS project] $ git push origin master
The above command will produce the following result:
To gituser@git.server.com: project.git
! [rejected]
master -> master (non-fast-forward)
error: bị lỗi khi push một refs để 'gituser@git.server.com: project.git'
Để đặt bạn từ history sử dụng, non-fast-forward updates bị bỏ qua
Merge những thay đổi xa trước khi gỡ bỏ lại. See the 'Note about
fast-forwards' section of 'git push --help' for details.
But Git does not allow Jerry to push his changes. Because Git identifies that remote repository and Jerry's local repository are asynchronous. Because of that, he can lose the history of the project. To avoid this mess, Git forgot this activity. Now, Jerry must first update the local repository and only after that, can he push but change it separately.
Call out the latest changes
Jerry runs the git pull command to synchronize his local repository with a remote repository.
[jerry @ CentOS project] $ git pull
The above command will produce the following result:
remote: Counting objects: 5, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 1), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From git.server.com:project
d1e19d3.cea2c00 master -> origin / master
First, rewinding đầu vào lại lại công việc của bạn ở đầu của nó .
Applying: Added my_strcpy function
After performing the pull operation, Jerry checks the log messages and finds Tom's commit details with the commit ID cea2c000f53ba99508c5959e3e12fff493ba6f69.
[jerry @ CentOS project] $ git log
The above command will produce the following result:
commit e86f0621c2a3f68190bba633a9fe6c57c94f8e4f
Author: Jerry Mouse
Date: Wed Sep 11 08:41:42 2013 +0530
Added my_strcpy function
commit cea2c000f53ba99508c5959e3e12fff493ba6f69
Author: Tom Cat
Date: Wed Sep 11 08:32:07 2013 +0530
Changed char pointer to const char pointer
commit d1e19d316224cddc437e3ed34ec3c931ad803958
Author: Jerry Mouse
Date: Wed Sep 11 08:05:26 2013 +0530
Changed return type of my_strlen to size_t
commit 19ae20683fc460db7d127cf201a1429523b0e319
Author: Tom Cat
Date: Wed Sep 11 07:32:56 2013 +0530
Initial commit
Now Jerry's local repository is fully synchronized with the remote repository. So he can push changes safely.
[jerry @ CentOS project] $ git push origin master
The above command will produce the result:
Counting objects: 5, done.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 455 bytes, done.
Total 3 (delta 1), reused 0 (delta 0)
To gituser@git.server.com: project.git
cea2c00.e86f062 master -> master
According to Tutorialspoint
Previous post: Push operation in HTML
Next lesson: Stash operation in Git
You should read it
- How to Create and Call PHP Functions
- Summary of trigonometric functions in Excel
- Complete financial functions in Excel you should know
- Shell functions
- Comparison functions in Excel - How to use comparison functions and examples using comparison functions
- Differentiate between SUM, SUMIF, SUMIFS and DSUM functions
- 6 useful functions in Google Sheets you may not know yet
- How to use math functions in C#
May be interested
- Rules of Survival: What's HOT in the content of Update ROS 6/1/2021?thus, the christmas activity will end after the player updates the rules of survival to version 6/1/2021, 2 weeks from the date of appearance. all features in the lobby remain the same, in particular, update ros 6/1/2021 is as follows.
- How to hide Listening Activity on Spotifyhideify listening to music in spotify is a great way to protect your privacy, although that can prevent friends from enjoying songs based on your music preferences.
- 10 dangerous things will happen to your body if you sit all daywhat happens to the body when you sit all day?
- WatchOS 10 will bring Widgets back to Apple Watchwith the watchos 10 update, it will let users scroll through a bunch of different widgets – to track activity, weather, stock tickers, calendar appointments, etc. – instead of having to launch the app,.
- How to create reports on Apple Watch activityapple apps will analyze and report activity for you, but you may want to manually export and view all your health data.
- Windows 10 collects and sends your activity history to Microsofton the reddit forum, many users are discussing and confirming that windows 10 collects activity history - activity history of applications that users use on the pc and sends it to microsoft.
- The suspect on the network was arrested after the provider shared VPN access history with the FBIvpn service providers often advertise their products as a way to surf the web anonymously, that they never record user activity. but a recent case shows that there are at least a few units that record user activity history.
- How to cancel scheduled Chkdsk activity in Windows 10chkdsk is very helpful, but can be time consuming if it is scheduled automatically. in this tutorial, you will learn how to cancel scheduled chkdsk activities in windows 10.
- How to update Win 7, update Windows 7 to the latest versionupdating windows 7 and security patches for windows 7 will help you limit the risk of dangerous malware or ransomware infections such as wannacry.
- Samsung Galaxy S23 receives June security update with many camera improvementsthe update to the s23 series will mainly focus on resolving autofocus issues and improving the night mode feature.