Git Staging Environment
In this page:
git add file_name
git add -A
git status
Staging Environment क्या है?
Git किसी file को तीन areas से track करता है: working directory जहाँ आप files edit करते हैं, staging environment (जिसे index भी कहते हैं) जहाँ आप mark करते हैं कि exactly कौन से changes अगली commit में जाने चाहिए, और repository जहाँ committed history permanently store होती है।
उदाहरण: What is the Staging Environment?
git status
git add से Changes Stage करना
Staging environment working directory और repository के बीच बैठता है, और git add वह command है जो किसी specific file की current content को इसमें move करता है, इसलिए जब आप अगली बार git commit चलाते हैं तो सिर्फ explicitly staged किए गए changes शामिल होते हैं।
उदाहरण: Staging Changes with git add
git add file.txt
git add -A से सभी Changes Stage करना
files को एक बार में एक stage करने के बजाय, git add -A पूरी repository scan करता है और एक single command में हर नई file, tracked file में हर modification, और हर deletion stage करता है, हर बदली हुई चीज़ शामिल करने वाली एक commit prepare करने का एक तेज़ तरीका देते हुए।
उदाहरण: Staging All Changes with git add -A
git add -A
git add -p से Partial Staging
git add -p (या --patch) हर modified file को changed lines के individual hunks में तोड़ता है और पूछता है कि हर hunk को अलग से stage करना है या नहीं, जो तब उपयोगी है जब एक single file में दोनों changes हों जिन्हें आप अभी commit करना चाहें और वे जिन्हें आप अलग से या बिल्कुल नहीं commit करना चाहें।
उदाहरण: Partial Staging with git add -p
git add -p
Changes Unstage करना
एक file जिसे stage किया गया है लेकिन अभी commit नहीं हुआ उसे git restore --staged (या पुराने git reset HEAD) से staging environment से हटाया जा सकता है, जो इसे actual edits delete या revert किए बिना working directory में वापस modified state में लौटा देता है।
उदाहरण: Unstaging Changes
git restore --staged file.txt
git addके बाद एक file edit करना और यह मान लेना कि नया edit staged है, जबकि latest changes stage करने के लिए आपको दोबाराgit addचलाना ज़रूरी है।- बिना
git statuscheck किएgit add .चलाना, ऐसी files stage करना जिन्हें आप commit नहीं करना चाहते थे, जैसे logs या secrets। - यह मानना कि staging area एक commit जैसा ही है, जबकि staged changes अभी भी बदले या unstaged जा सकते हैं और अभी history में नहीं हैं।
Chapter Quiz — Complete all 18 topics to unlock
0/18 topics done
Complete these topics first:
- Git init Command
- Git New Files
- Git Staging Environment
- Git clone Command
- Git status Command
- Git help Command
- Git add Command
- Git commit Command
- Git tags Command
- Git stash Command
- Git log Command
- Git diff Command
- Git show Command
- Git rm Command
- Git mv Command
- Git restore Command
- Git clean Command
- Git ignore (.gitignore)