Category: News
Specbee: How to create and apply a patch with Git Diff and Git Apply commands for your Drupal website
Akshay Devadiga
24 Jan, 2023
Git has been a reliable version control tool for a large number of closed and open-source projects. With Drupal being an extremely collaborative open-source content management framework, a trackable, transparent, and distributed version control system like Git is a perfect fit. Git replaced a long-time version control partner – CVS – in early 2011 and became every Drupal developer and contributor’s favorite tool for its security, distributed nature, agile workflow, and of course, being open source!
If you’re a Drupal developer, you should be familiar with patches already. Patches are like band-aids. They are small pieces of code that are added on top of already existing code files to support it or fix any issues. Different types of patches include bug fixes, security vulnerability fixes, performance enhancements, styling fixes, etc. If you are a regular contributor to the Drupal project, you should know that to fix an issue in Drupal core or contributed modules, you must submit a patch to an issue in the issues queue. These patches are then examined and tested by the module maintainer and applied if found beneficial.
This is a revised version of the article. We’d like to thank Anktiha Shetty and Pratik Kadambari for all their great inputs!
There are different ways to apply a Git patch. Let’s learn more about various Git Diff commands and how to create/apply a patch with the help of Git diff and Git apply. We will assume that you have already cloned/obtained a copy of the project in your local repository and have pulled the latest changes so you’re not working on an older version of the project. Take a look at some Github best practices here.
What does the Git Diff command do?
Git diff is a command to output the changes between two sources inside the Git repository. The data sources can be two different branches, commits, files, etc.
The common use cases of git diff commands are listed below.
• $ git diff
This command will output all the modified changes which are not added to git or staged.
• $ git diff filename
This will output the changes of that current file to its previous committed state.
• $ git diff branch_name
This will output the modifications of the current branch to the mentioned branch to its previous committed state.
• $ git diff –staged (or –cached) path/to/file
Once the changes are added to Git or moved to staging, you will not be able to see the diff of the files. To see the staged changes, you can use diff with –staged or –cached option.
• $ git diff HEAD
To see the changes from both staged and unstaged changes (not untracked files) together, you can use the git diff HEAD command. If you have all changes staged for commit, then both commands i.e., –staged/–-cached and HEAD will output the same.
• $ git diff commit_id1 commit_id2
To see the difference between any two commits you can use this git diff command where you need to mention the two commit ids.
If you want to see the list of commits made in the Git repo, use the command $ git log. This will list out all the commits (starting from the latest commit) along with their respective commit ids, the author (developer) and the date it was committed on.
Creating a Git patch with git diff
To create a Git patch, we can use any of the git diff commands to get the changes. We then need to save the changes to a file which can be used as below.
• $ git diff > my_custom_patch_file.patch
Apply the Git Patch
Drupal developers will want to apply Git patches frequently to update changes or to fix bugs. Developers will create a patch file that can be used by other developers according to their needs. To apply a git patch to the current branch use the following command.
• $ git apply patch_file.patch
Try the above command with the -v or –verbose option. It will cause additional information about the current patch being applied to be reported (as shown below).
Other useful Git patch apply conditions:
1. Working with trailing white spaces
Use –whitespace option to handle such situations.
Here the patch is created accidentally with trailing whitespaces (as shown below).
If the patch is applied as is: $git apply patch_file.patch
The patch will be applied (with whitespace warnings) and will still retain the whitespaces which can cause linting errors.
To fix trailing whitespaces while applying the patch, use the option –whitespace=fix, the patch will be applied, and trailing whitespaces will be removed.
Usage: $git apply –whitespace=fix patch_file.patch
2. Checking the patch before applying
To check before applying the patch, use option –check
The command will show no warnings and errors if the patch is applied cleanly.
3. To see file statistics before applying the patch
Use –stat option with the git apply command. It will list all files which will be changed upon applying the patch.
The patch will only show information, and will not be applied.
To apply patch along with “stat” options add option –apply in command.
Usage: $git apply –stat –apply patch_file.patch
4. To apply only changes that are getting removed
Use Option –no-add with git apply.
For example:
Here only changes in red will be applied and green will be excluded.
Usage: $git apply –no-add patch_file.patch
5. Exclude and include the patch to be applied to selected files
Use –exclude option to exclude files from applying patch change.
$git apply –exclude=file_name.ext patch_file.patch
Changes on other files, excluding mentioned file, will be reflected.
Vice versa:
$git apply –include=file_name.ext patch_file.patch
Changes only on the mentioned file will be reflected.
Rubber Duck Dev Show Episode 70 | Teaching Young Developers with Melissa Amaya
Increasing 5G Quality of Experience (QoE) Using SONiC and Open Packet Broker
5G has revolutionized the use of data services for mobile users worldwide, providing high data rate / high capacity, low latency, and massive connectivity. These characteristics of 5G have forced mobile carriers to increase their focus on ways to improve network service and their customer’s Quality of Experience (QoE). This requires sophisticated network monitoring to […]
The post Increasing 5G Quality of Experience (QoE) Using SONiC and Open Packet Broker appeared first on Linux.com.
Start this year fresh with Mozilla’s tech challenge
If you’ve already ditched your new year’s goals, we’re here to help. How about a refreshening of your online life with new habits and routines? Are there newsletters you don’t read anymore? Mobile apps you no longer use? Or social media platforms you’ve left (ahem, Twitter)? We want to help. We’ve put together a month-long […]
The post Start this year fresh with Mozilla’s tech challenge appeared first on The Mozilla Blog.
texinfo @ Savannah: Texinfo 7.0.2 released
We have released version 7.0.2 of Texinfo, the GNU documentation format. This is a minor bug-fix release.
It’s available via a mirror (xz is much smaller than gz, but gz is available too just in case):
http://ftpmirror.gnu.org/texinfo/texinfo-7.0.2.tar.xz
http://ftpmirror.gnu.org/texinfo/texinfo-7.0.2.tar.gz
Please send any comments to bug-texinfo@gnu.org.
Full announcement:
https://lists.gnu.org/archive/html/info-gnu/2023-01/msg00008.html
Windows 3.x VDDVGA
Aik aur Subh | Morning Show | 19th January | Dr. Usman Aftab & Dr. Zafar Iqbal | aur Life
#morningshow #AikaurSubh #aurLife
Aik aur Subh is a daily broadcast morning show based on the idea of open-source ethics. It consists of three segments: a fitness show for men and women with Wasaf Naeem and a Gupshup segment with guests, i.e., celebrities, politicians, famous personalities, etc. The show is hosted by Hafiz Najam Us Saqib and Haleema Zulfiqar, who gives the audience an inside look at the lives of the people who help Pakistan wake up in the morning.
Guests:
Dr. Usman Aftab
Dr. Zafar Iqbal
Guest Details:
Dr. Usman Aftab Ahmad is a gastroenterologist and hepatologist (MBBS), a fellow of the Royal College of Physicians of Edinburgh, and a member of the Royal College of Physicians of London (CCT in gastroenterology and internal medicine). Dr. Usman Aftab has vast experience in gastroenterology and hepatology. He is a trainer at the Yorkshire School of Endoscopy.
Zafar Iqbal is Chairman and Professor, of the Department of Media and Communication Studies, at the International Islamic University, Pakistan. Zafar Iqbal, Ph.D., has more than 23 years of teaching and research experience. He received a doctorate in mass communication in 2003 and has published in reputed national and international journals. During the last 10 years.
Subscribe aurlife
https://www.youtube.com/c/aurlifeofficial
Like aurlife on Facebook:
https://www.facebook.com/aur.Life
Follow aurlife on Twitter:
https://twitter.com/aurLifeOfficial
Follow aurlife on Instagram:
https://www.instagram.com/aurlifeofficial
ପୂର୍ବରୁ କେମିତି ଦିଶୁଥିଲା ଭୁବନେଶ୍ୱର? ସେବେ ଓ ଏବେ..
OdishaTV is Odisha’s no 1 News Channel. OTV being the first private satellite TV channel in Odisha carries the onus of charting a course that behoves its pioneering efforts.
Accordingly its charter objectives are FREE, FAIR and UNBIASED. OTV delivers reliable information across all platforms: TV, Internet and Mobile.
Stay tuned for all the breaking news !
Visit Our Website https://odishatv.in/
News In Odia: https://khabar.odishatv.in/
Android App: https://bit.ly/OTVAndroidApp
iOS App: https://bit.ly/OTViOSApp
Watch Live: https://live.odishatv.in/
YouTube: https://goo.gl/Ehz6OP
Watch our latest news in English: https://bit.ly/3wTgKxc
Facebook: https://www.facebook.com/otvkhabar
OTV English Facebook : https://www.facebook.com/otvnews
Telegram @otvtelegram @otvkhabar
Twitter: https://twitter.com/otvnews
Instagram: https://www.instagram.com/otvnews/
#OdishaTV #OTV