← Back to Git Course | Chapter 2: Basic Commands | Lesson 3 of 18

Git Staging Environment

Staging environment किसी file को edit करने और उसे commit करने के बीच का middle step है, आपको exactly यह चुनने देते हुए कि कौन से changes -- पूरी files या यहाँ तक कि individual lines -- अगली commit में जाएँ।
Syntax
bash
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?

bash
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

bash
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

bash
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

bash
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

bash
git restore --staged file.txt
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. git add के बाद एक file edit करना और यह मान लेना कि नया edit staged है, जबकि latest changes stage करने के लिए आपको दोबारा git add चलाना ज़रूरी है।
  2. बिना git status check किए git add . चलाना, ऐसी files stage करना जिन्हें आप commit नहीं करना चाहते थे, जैसे logs या secrets।
  3. यह मानना कि staging area एक commit जैसा ही है, जबकि staged changes अभी भी बदले या unstaged जा सकते हैं और अभी history में नहीं हैं।

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.