Patch operation in Git
The patch is a text file, its content is similar to git diff, but in parallel with the code, it also has metadata about commits such as commit IDs, dates, commit messages . We can Create a patch from commits and others can apply them to their repository.
Jerry performs the strcat function for his project. Jerry can create a patch of his code and send it to Tom. After that, he can apply the received patch to his code.
Jerry uses the git format-patch command to create a patch for the latest commits. If you want to create a patch for a specific commit, then use COMMIT_ID with the format-patch command.
[jerry @ CentOS project] $ pwd
/ home / jerry / jerry_repo / project / src
[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 my_strcat function"
[master b4c7f09] Added my_strcat function
1 files changed, 13 insertions (+), 0 deletions (-)
[jerry @ CentOS src] $ git format-patch -1
0001-Added-my_strcat-function.patch
The above command creates the .patch files inside the current working directory. Tom can use the patch to edit his file. Git provides two commands to apply patches that are git am and git apply, in a separate way. Git applies to editing internal files without creating commits, while git am modifying the file and also creating commits.
To apply patch and commit, use the following command:
[tom @ CentOS src] $ pwd
/ home / tom / top_repo / project / src
[tom @ CentOS src] $ git diff
[tom @ CentOS src] $ git status –s
[tom @ CentOS src] $ git apply 0001-Added-my_strcat-function.patch
[tom @ CentOS src] $ git status -s
M string_operations.c
?? 0001-Added-my_strcat-function.patch
This patch has been successfully applied, now we can observe the modifications using the git diff command.
[tom @ CentOS src] $ git diff
The above command produces the following result:
diff --git a / src / string_operations.cb / src / string_operations.c
index 8ab7f42.f282fcf 100644
--- a / src / string_operations.c
+++ b / src / string_operations.c
@@ -1,5 +1,16 @@
#include
+ char * my_strcat (char * t, char * s)
diff --git a / src / string_operations.cb / src / string_operations.c
index 8ab7f42.f282fcf 100644
--- a / src / string_operations.c
+++ b / src / string_operations.c
@@ -1,5 +1,16 @@
#include
+ char * my_strcat (char * t, char * s)
+
{
+
char * p = t;
+
+
+
while (* p)
++ p;
+
while (* p ++ = * s ++)
+;
+ return t;
+
}
+
size_t my_strlen (const char * s)
{
const char * p = s;
@@ -23,6 +34,7 @@ int main (void)
{
According to Tutorialspoint
Previous post: Tag operation in Git
Next lesson: Managing branches in Git
You should read it
- Commit in Git
- 5 best patch management and monitoring software
- Microsoft releases urgent patch for printer error emergency patch
- Update the latest patch for Windows XP to prevent dangerous security risks
- Del command in Windows
- Microsoft updated Patch Tuesday in October 2020, patching the 'Ping of Death' vulnerability on Windows 10
- Apple patched many zero-day bugs in iOS 15.4.1 and macOS 12.3.1 updates
- Download an emergency Windows patch right away, fix two critical vulnerabilities, affecting every Windows version
May be interested
- Windows 10 and 11 PC users need to update this patch immediatelymicrosoft has released cumulative updates for windows 10 and 11 pc systems via patch tuesday this month.
- Microsoft patched 15 bugs, continued to patch SSL certificatesmicrosoft finally released an update patch after 4 days of detailed information leakage.
- Microsoft releases new Patch Tuesday update for Windows 10microsoft has released a series of new cumulative updates for win 10 as part of the monthly patch tuesday update cycle, bringing changes and fixes to improve the quality and security of windows 10.
- Things to know about Android security patchesin some cases, such as turning off automatic updates, you may not be able to run the latest security patch. here's how to check the version of android you're running and how to upgrade if you don't have the latest version of android.
- Apple Patches Zero-Day Vulnerability That Could Let iPhones, iPads, and MacBooks Get Hackedapple has just released a security update to patch two zero-day vulnerabilities. in it, one has been made public and another is being exploited by hackers to penetrate iphones and macs. these are the first zero-day vulnerabilities that apple will patch in 2022.
- Microsoft is about to release Patch Tuesdaymedia reports say microsoft is preparing to release nine patches in the patch tuesday package next week, including five that are 'important.'
- Push operation in HTMLjerry modifies the previous commits using the git commit -a operation (signing changes) and he is ready to push the changes. push operation saves permanent data to git repository. after a successful push operation, other programmers can observe jerry's changes.
- Intel released a new patch to fix the Specter and Meltdown vulnerabilitiesintel has officially released the latest and stable patch for the two specter and meltdown vulnerabilities, causing it to restart automatically. this patch is for 6th generation processors (skylake), 7 (kaby lake) and 8 (coffee lake) including core i, core x, scalable xeon and xenon d.
- Just one page access, Windows PC can also be hackedjust click the malicious link or open a website, your computer can be hacked.
- Apple instructs how to defeat Mac Defenderapple is about to unveil the 'special remedy' for malware mac defender. until the official patch reached the user, 'apple' did not forget to post the instructions ...