Git patch Command
In this page:
git diff > patch_file.patch
git format-patch commit_hash
git apply patch_file.patch
Diff से Patches बनाना
git diff > changes.patch current uncommitted differences को एक plain-text patch file की तरह capture करता है, जिसे कोई भी git apply से same codebase की अपनी copy पर apply कर सकता है — repository access या एक pull request की ज़रूरत के बिना एक fix share करने का एक lightweight तरीका।
उदाहरण: Creating Patches with Diff
git diff > changes.patch
Format-Patch से Patches बनाना
git format-patch <commit> एक raw diff से आगे जाता है: यह प्रति commit एक .patch file produce करता है, हर एक author, date, और commit message सहित एक पूरे email-style message की तरह formatted — specifically इतनी information preserve करने के लिए designed कि receiving end original commit को उसकी file changes ही नहीं, exactly recreate कर सके।
उदाहरण: Creating Patches with Format-Patch
git format-patch a1b2c3d
Patch Integrity Check करना
git apply --check (या क्या बदलेगा इसकी summary के लिए --stat) आपको actually apply करने से पहले अपनी current working directory के against एक patch validate करने देता है, बिना कोई file छुए एक ऐसी patch पकड़ते हुए जो conflicting local changes की वजह से cleanly apply नहीं होगी।
उदाहरण: Checking Patch Integrity
git apply --check changes.patch
git apply --stat changes.patch
Patches Apply करना
git apply <patch> आपकी working directory पर एक plain diff-style patch को एक unstaged change की तरह apply करता है, file contents update करते हुए लेकिन कोई commit न बनाते हुए — आपको फिर भी बाद में खुद result git add और commit करना होगा।
उदाहरण: Applying Patches
git apply changes.patch
Patches Apply और Commit करना
git am <patch> specifically format-patch से आई patches के लिए बना है: यह changes apply करता है AND patch file में embedded author, date, और message इस्तेमाल करके original commit recreate करता है — effectively किसी और की commit को आपकी repository में transplant करते हुए जैसे आपने इसे pull से receive किया हो।
उदाहरण: Applying and Committing Patches
git am 0001-fix-login-bug.patch
git diffसे एक patch बनाना और commit information की उम्मीद करना, जबकिgit format-patchमें author और message शामिल होते हैं।- बिना
git apply --checkके एक अलग base commit पर एक patch apply करना, ताकि यह बीच में fail हो जाए। - एक
format-patchfile के लिएgit applyइस्तेमाल करना और एक commit की उम्मीद करना, जबकिgit amइसे एक commit की तरह apply करता है।
- Advanced commands में submodules, hooks, और GitFlow workflows शामिल हैं।
git bisectऔरgit blameयह track करने में मदद करते हैं कि changes कब और कहाँ हुए।git archiveऔरgit patchchanges package और share करते हैं।
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: