टेस्टर्स के लिए Git बेसिक्स
Git एक version control system है: यह project की history को commits नाम के snapshots की एक chain के रूप में record करता है, और हर commit के पास एक unique id, author, date, message और उससे पहले वाले commit का link होता है। जब कोई developer checkout में VAT rounding ठीक करके change को 3f9c2ab के रूप में commit करता है, तो वह commit history में एक स्थायी point बन जाता है: कोई भी देख सकता है कि कौन-सी lines बदलीं, किसने और कब बदलीं, और ठीक उसी version को टेस्ट कर सकता है।
Tester के लिए Git code लिखने से ज़्यादा यह जानने के बारे में है कि आप ठीक क्या टेस्ट कर रहे हैं: कौन-सा version, कौन-सा change, और उस change ने और क्या-क्या छुआ।
यह क्यों ज़रूरी है
"आपने कौन-सा build टेस्ट किया?" — Git इस सवाल का सटीक जवाब देता है। Commit id के बिना failure को reproduce करना मुश्किल है, और कोई साबित नहीं कर सकता कि retest fix वाले version पर चला। "main पर 3f9c2ab में fail होता है" को team का कोई भी reproduce कर सकता है।
Git यह भी दिखाता है कि क्या बदला: पिछले tested version के बाद का diff regression tests चुनने का सीधा input है। और automated tests, test data और pipeline files उसी repository में रहती हैं जिसमें product code है, इसलिए उन्हें maintain करने का मतलब है developer की तरह commit, branch और merge करना।
Repository, commit और वे तीन जगहें जहाँ से change गुज़रता है
Repository एक project folder और उसकी पूरी history है, जिसे Git एक hidden .git directory में रखता है। Team की shared copy, यानी remote, जिसे आम तौर पर origin कहते हैं, एक server पर रहती है; git clone उसे पूरी history के साथ आपकी machine पर copy करता है। बाद में git fetch नए commits download करता है और remote की branches अब कहाँ point करती हैं, यह origin/main जैसे नामों में दर्ज करता है, आपकी files को छुए बिना; git pull आपकी current branch को भी update कर देता है, और git push आपके अपने commits origin पर भेजता है।
एक change तीन जगहों से गुज़रता है: working tree (वे files जिन्हें आप edit करते हैं), staging area या index (git add से चुने गए changes) और history (git commit staged चीज़ों का snapshot record करता है)। Git हर commit को एक hash से नाम देता है, यानी commit के content और history से निकाला गया fixed-length fingerprint: 40 hexadecimal characters (ज़्यादातर repositories में SHA-1), जो आम तौर पर पहले सात या ज़्यादा characters तक छोटा करके दिखाया जाता है, जैसे 3f9c2ab। एक character बदलते ही id बदल जाती है, इसलिए commit id ठीक एक version की पहचान है। SHA-1 जनरेटर यह असर किसी भी text पर दिखाता है; Git commit का hash अपने internal format में बनाता है, इसलिए इससे आपको commit id नहीं मिलेगी।
$ git clone https://git.example.com/shop/web.git # the repository and its history
$ cd web
$ git fetch # later: get new commits from origin; files untouched
$ git pull # fetch, then bring your current branch up to date
$ git status # what is modified, staged or untracked
$ git add tests/checkout/vat.spec.ts
$ git commit -m "Add VAT test for a total ending in .005"
$ git push # send your new commits to originBranches, HEAD और merge
Branch एक movable नाम है जो एक commit की ओर point करता है; branch पर हर नया commit उस नाम को आगे बढ़ा देता है। main (पुरानी repositories में अक्सर master) में आम तौर पर integrated product रहता है, और developers हर change के लिए एक short-lived branch बनाते हैं, जैसे fix/vat-rounding, ताकि अधूरा काम किसी को परेशान न करे। HEAD वह है जिसे आपने अभी check out किया है, आम तौर पर कोई branch।
Merge एक branch के commits को दूसरी branch में लाता है। अगर branch शुरू होने के बाद target आगे नहीं बढ़ा, तो Git बस उसका नाम आगे बढ़ा देता है (fast-forward); अगर दोनों तरफ़ नए commits हैं, तो Git दो parents वाला merge commit बनाता है। अगर दोनों तरफ़ एक ही lines बदली गईं, तो Git merge conflict पर रुक जाता है और कोई इंसान result लिखता है। बिना conflict वाला merge भी ऐसे changes जोड़ता है जो पहले कभी साथ में नहीं चले, इसलिए merged build को अपना अलग test चाहिए। Branching strategies और pull requests अगले lesson में हैं।
git log --graph में हर * एक commit है और lines उसके parents तक जाती हैं; brackets में लिखे नाम बताते हैं कि branches, tags और HEAD कहाँ point कर रहे हैं।
fix/vat-rounding release v2.3.0 से शुरू होती है और उस पर एक commit होता है जबकि main पर दो; उसे वापस merge करने से दो parents वाला merge commit 9e41d07 बनता है।mainintegrated product वाली branchfix/vat-roundingएक change, अलग रखा हुआ
- 1
mainआंतरिक रूप से: Releasev2.3.0का tag1d2e3f4पर Tester का आख़िरी tested version - 2
mainसेfix/vat-roundingतक: उसी commit पर branch बनीgit switch -c fix/vat-rounding - 3
mainआंतरिक रूप से: Commit5b0a9f4: minimum order 50.00 SAR साथीmainपर commit करते रहते हैं - 4
mainआंतरिक रूप से: Commitc7d2e18: invoice के Arabic labels - 5
fix/vat-roundingआंतरिक रूप से: Commit3f9c2ab: VAT rounding fix अभी तक सिर्फ़ इसी branch में - 6
fix/vat-roundingसेmainतक: Merge हुई: merge commit9e41d07दो parents:c7d2e18और3f9c2abgit merge fix/vat-rounding - 7
mainआंतरिक रूप से: Tester नई चीज़ों की list निकालता हैv2.3.0के बाद चार commits: regression scopegit log --oneline v2.3.0..main
समय ऊपर से नीचे चलता है। हर lane एक branch का नाम है जो हर नए commit के साथ आगे बढ़ता है।
$ git switch -c fix/vat-rounding # new branch at the current commit, switch to it
$ git commit -am "Fix VAT rounding for totals ending in .005" # -a stages edited files
$ git switch main
$ git pull # fast-forward: two new commits from colleagues
$ git merge fix/vat-rounding # both sides moved on: Git makes a merge commit
$ git log --oneline --graph -5
* 9e41d07 (HEAD -> main) Merge branch 'fix/vat-rounding' into main
|\
| * 3f9c2ab (fix/vat-rounding) Fix VAT rounding for totals ending in .005
* | c7d2e18 (origin/main) Add Arabic labels to the invoice PDF
* | 5b0a9f4 Update minimum order total to 50.00 SAR
|/
* 1d2e3f4 (tag: v2.3.0) Release 2.3.0log, show और diff से history पढ़ना
git log commits को सबसे नए से पुराने क्रम में दिखाता है; git show एक commit और उसके changes दिखाता है; git diff किन्हीं दो versions की तुलना करता है। Tag किसी एक commit का fixed नाम है, आम तौर पर v2.3.0 जैसी कोई release।
नीचे के diff में --- और +++ पुरानी और नई file के नाम बताते हैं, - से शुरू होने वाली lines हटाई गईं, + से शुरू होने वाली जोड़ी गईं, और @@ -9,5 +9,5 @@ का मतलब है कि excerpt line 9 से शुरू होता है और दोनों versions में पाँच lines तक फैला है; दूसरे @@ के बाद का text बस file की एक पिछली line है, जो orientation के लिए दिखाई जाती है।
git log --oneline v2.3.0..main:mainमें वह सब जो releasev2.3.0में नहीं है।git log --oneline -- src/checkout/: सिर्फ़ वे commits जिन्होंने checkout folder को छुआ।git diff --stat v2.3.0 main: दो versions के बीच बदली files और lines की गिनती।git tag --contains 3f9c2ab: वे releases जिनमें कोई fix पहले से शामिल है।
$ git diff v2.3.0 main -- src/checkout/vat.ts
diff --git a/src/checkout/vat.ts b/src/checkout/vat.ts
index 4b1e2c0..9d7a3f1 100644
--- a/src/checkout/vat.ts
+++ b/src/checkout/vat.ts
@@ -9,5 +9,5 @@ import { roundHalfUp } from './money';
// VAT rate in this example: 15 %
export function vatFor(net: number): number {
const rate = 0.15;
- return Math.round(net * rate * 100) / 100;
+ return roundHalfUp(net * rate, 2);
}Worked example: पिछली release के बाद क्या बदला
आपने पिछले हफ़्ते release v2.3.0 टेस्ट की थी; आज आपसे latest main पर regression pass माँगा गया है। Application खोलने से पहले आप Git से पूछते हैं कि क्या बदला; commands और उनका output इस section के आख़िर में हैं। उन्हें file दर file पढ़ें:
vat.ts: VAT rounding की एक line बदली। ऐसी amounts टेस्ट करें जिनका VAT आधे हलला पर ख़त्म होता है, जैसे 1.10 SAR की net price (VAT 0.165)।git grepदिखाता है कि totals और refunds भीvatForcall करते हैं, इसलिए refunds भी scope में आते हैं।min-order.ts: minimum order अब 50.00 SAR है। Boundary value analysis की तरह 49.99 और 50.00 टेस्ट करें; अगर किसी ticket या release note में इस change का ज़िक्र नहीं है, तो टेस्ट करने से पहले पूछें।labels.ar.json: invoice के नए Arabic labels। Arabic PDF invoice और उसका right-to-left layout जाँचें।vat.spec.ts: नए unit tests। जिन values को ये cover करते हैं उन पर कम manual मेहनत चाहिए; जो छूट गईं वे आपकी list में जाती हैं।- Test report और हर bug report में लिखें: "
mainपर9e41d07में regression,v2.3.0के बाद के changes"।
$ git fetch origin
$ git log --oneline v2.3.0..origin/main
9e41d07 (origin/main) Merge branch 'fix/vat-rounding' into main
3f9c2ab Fix VAT rounding for totals ending in .005
c7d2e18 Add Arabic labels to the invoice PDF
5b0a9f4 Update minimum order total to 50.00 SAR
$ git diff --stat v2.3.0 origin/main
src/checkout/min-order.ts | 4 ++--
src/checkout/vat.ts | 2 +-
src/invoice/labels.ar.json | 18 ++++++++++++++++++
tests/checkout/vat.spec.ts | 21 +++++++++++++++++++++
4 files changed, 42 insertions(+), 3 deletions(-)
$ git grep -n "vatFor(" origin/main -- src
origin/main:src/checkout/total.ts:27: const vat = vatFor(net);
origin/main:src/checkout/vat.ts:10:export function vatFor(net: number): number {
origin/main:src/refunds/refund.ts:41: return amount + vatFor(amount);आम गलतियाँ
- Commit id या tag की जगह "latest build" पर bug report करना: तब कोई failure reproduce नहीं कर सकता, न साबित कर सकता है कि retest fix पर चला।
- पुरानी copy टेस्ट करना:
git statusकोoriginकी हालत सिर्फ़ आपके आख़िरीgit fetchतक की पता होती है। - Diff पढ़े बिना commit messages पर भरोसा करना: "refactor" नाम का commit भी business rule बदल सकता है।
- Secrets,
.envfiles, test reports या screenshots commit करना।.gitignoreइस्तेमाल करें; बाद में delete किया गया secret history में रहता है, इसलिए तुरंत बताएँ ताकि उसे revoke किया जा सके। - "fix" जैसे messages के साथ बड़े commits करना: तब history किसी को नहीं बताती कि क्या बदला और क्यों, और किसी एक change को अलग से ढूँढा या undo नहीं किया जा सकता।
QA का नज़रिया
Tester रोज़ Git का एक छोटा हिस्सा इस्तेमाल करते हैं: वे test हो रहे version को ठीक-ठीक record करते हैं, regression tests चुनने के लिए पिछले tested version के बाद का log और diff पढ़ते हैं, failure reproduce करने के लिए किसी commit को check out करते हैं, और automated tests को repository में रखते हैं, जहाँ CI push या merge जैसे Git events पर शुरू होता है। ISTQB Foundation syllabus इस अनुशासन को configuration management कहता है: test items और testware की unique पहचान होती है और वे version control में रहते हैं।
हर defect को ठीक करने वाला commit या pull request माँगें और उसे defect record में link करें; confirmation testing से पहले जाँचें कि fix आपके build में है। Diff की हर line समझना ज़रूरी नहीं: file names, function names और change का size यह पूछने के लिए काफ़ी हैं कि "इसे और कौन इस्तेमाल करता है?", यही सवाल regressions पकड़ता है।
अभ्यास
Release history पढ़ें और retest की योजना बनाएँ
आपने एक shop application की आख़िरी release v1.8.0 टेस्ट की थी। नीचे दिए output से नए commits, branch और merge commit पहचानें, टेस्ट करने वाले areas की list बनाएँ, और तय करें कि tested version को कैसे पहचानेंगे।
$ git log --oneline --graph v1.8.0..main
* a41f9c0 (HEAD -> main) Merge branch 'feature/saved-cards' into main
|\
| * 7be2d15 Mask card number except the last 4 digits
| * 0c93e6a Add saved cards page
* | e5d8b72 Fix account lockout after 5 failed logins
|/
* 52aa1f3 Change password reset link expiry to 30 minutes- Graph को नीचे से ऊपर पढ़ें: branch कहाँ शुरू हुई और कहाँ merge हुई?
- नए commits को product area के हिसाब से group करें।
- पिछले lessons की techniques से हर area के लिए दो या तीन test ideas लिखें।
- अपनी report के लिए version line और team के लिए एक सवाल लिखें।
मॉडल उत्तर दिखाएँ
पाँच commits नए हैं। feature/saved-cards branch 52aa1f3 से शुरू हुई और उसमें 0c93e6a और 7be2d15 हैं; इस बीच e5d8b72 main पर commit हुआ।
a41f9c0 merge commit है: इसका पहला parent e5d8b72 (main का पिछला tip) और दूसरा parent 7be2d15 (branch का tip) है। दोनों lines शायद कभी साथ में टेस्ट नहीं हुईं, इसलिए merged build को अपना अलग pass चाहिए।
Authentication: 30 minutes से ठीक पहले और ठीक बाद password reset links, और दो बार इस्तेमाल हुआ link; 4, 5 और 6 failed logins। Payments: saved cards जोड़ना और list करना, और page, API responses, emails और logs में सिर्फ़ आख़िरी 4 digits दिखना।
Version line: "main पर a41f9c0 में regression, v1.8.0 के बाद के changes"। सवाल: क्या 30 minutes की expiry किसी ticket से आई है, और क्या यह release से पहले भेजे गए links पर भी लागू होती है?
अक्सर पूछे जाने वाले सवाल
अगर मैं सिर्फ़ manual testing करता हूँ, तो क्या मुझे Git चाहिए?
आपको इसका पढ़ने वाला हिस्सा चाहिए: commit ids, tags, log और diff, ताकि आप जानें कि कौन-सा version टेस्ट किया और उसमें क्या बदला। Hosting services वही history browser में दिखाती हैं, तो शुरुआत वहीं से कर सकते हैं। Commits लिखना और conflicts सुलझाना तब ज़रूरी होता है जब आप automated tests maintain करते हैं।
Git और GitHub में क्या फ़र्क है?
Git version control tool है; यह आपकी machine पर चलता है, और इसके ज़्यादातर commands network के बिना भी काम करते हैं। GitHub, GitLab और Bitbucket ऐसी services हैं जो remote repositories host करती हैं और Git के ऊपर pull requests, issue tracking और CI pipelines जोड़ती हैं।
git fetch और git pull में क्या फ़र्क है?
git fetch नए commits download करता है और origin/main जैसी remote-tracking branches update करता है, लेकिन आपकी files और branch को नहीं छूता। git pull पहले fetch करता है और फिर आपकी current branch को update करता है: अगर आपके अपने कोई नए commits नहीं हैं तो वह fast-forward करता है; अगर दोनों तरफ़ नए commits हैं तो उन्हें merge करना होगा या rebase (आपके commits को नए commits के ऊपर दोबारा लगाना), और Git के हाल के versions रुककर आपसे --no-rebase, --rebase या pull.rebase setting से चुनने को कहते हैं।
क्या bug reproduce करने के लिए पुराना commit check out करना सुरक्षित है?
हाँ। git checkout 3f9c2ab (या git switch --detach 3f9c2ab) उस version को "detached HEAD" state में working tree में ले आता है: आप उसे build और test कर सकते हैं, और git switch main आपको वापस ले जाता है। पहले अपने changes commit कर लें या git stash से अलग रख दें, क्योंकि अगर वे overwrite होने वाले हों तो Git switch करने से मना कर देता है।
संदर्भ
- Reference — Gitहर Git command और उसके options का आधिकारिक reference, काम के अनुसार समूहित — setup, branching, sharing, patching, inspection और debugging।
- Pro Git, 2nd Edition (Scott Chacon and Ben Straub)Pro Git किताब, ऑनलाइन मुफ़्त पढ़ने के लिए: Git की बुनियादी बातें, branching और merging, distributed workflows, और Git अपना डेटा कैसे स्टोर करता है।
- ISTQB Certified Tester Foundation Level (CTFL) v4.0सॉफ़्टवेयर टेस्टिंग का फ़ाउंडेशन पाठ्यक्रम: टेस्ट स्तर और प्रकार, टेस्ट डिज़ाइन तकनीकें, टेस्ट प्रबंधन और टूल।
Mutqan tools से अभ्यास करें
दो टेक्स्ट की लाइन-दर-लाइन या शब्द-दर-शब्द तुलना करें और अंतर हाइलाइट करें।
बदलाव के विवरण और प्रभावित तथा संबंधित मॉड्यूल की सूची से रिग्रेशन सिनेरियो जनरेट करें।
ब्राउज़र की WebCrypto API से टेक्स्ट का SHA-1 हैश बनाएँ।
और गहराई से
इस topic में आपकी प्रगति
प्रगति ट्रैक करने के लिए साइन इन करें
Topics पूर्ण चिह्नित करें, जहाँ छोड़ा था वहीं से जारी रखें और specialisation परीक्षाएँ खोलें।