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

Git add Command

git add picture लेने से पहले frame में कौन सी photos रखनी हैं यह चुनने जैसा है। आप exactly चुनते हैं कि कौन सी बदली हुई files अगले snapshot में जाएँ।
Syntax
bash
git add file_name
git add file1 file2
git add .

एक Single File Stage करना

exactly एक file stage करने के लिए, उसके exact path के साथ git add <filename> चलाएँ -- यह उस file के current contents को staging area में copy कर देता है आपकी अगली commit के candidate की तरह, बिना आपके बदली हुई किसी दूसरी चीज़ को छुए।

उदाहरण: Staging a Single File

bash
git add index.html

कई Files Stage करना

आप एक बार में एक file तक limited नहीं हैं -- git add file1.txt file2.txt एक single command में कई specific files stage करता है, जो तब handy है जब आपने कुछ related files छुई हों लेकिन बाकी untouched छोड़ना चाहते हों।

उदाहरण: Staging Multiple Files

bash
git add file1.txt file2.txt

सभी Changes Stage करना

जब आपने कई folders में बिखरी files modify की हों, हर एक individually stage करना tedious है -- git add . (current folder और नीचे सब कुछ stage करना) या git add -A (पूरी repository में हर change stage करना) इसे एक बार में handle करता है।

उदाहरण: Staging All Changes

bash
git add .
git add -A

File Type से Stage करना

Wildcards आपको नाम के बजाय pattern से stage करने देते हैं -- git add *.js current directory में हर JavaScript file stage करता है, जो तब उपयोगी है जब आप सिर्फ code changes commit करना चाहें और deliberately config या data files unstaged छोड़ना चाहें।

उदाहरण: Staging by File Type

bash
git add *.js

Interactive Staging

Interactive staging (git add -p) आपको hunks नाम के छोटे chunks में किसी file के changes में walk through करवाता है, आपको हर एक individually accept या skip करने देते हुए -- तब ज़रूरी जब एक single file एक unrelated debug print को उस real fix के साथ mix करे जिसे आप commit करना चाहते हैं।

उदाहरण: Interactive Staging

bash
git add -p
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.txt इस्तेमाल करना और फिर file दोबारा edit करना, यह उम्मीद करते हुए कि newest edit commit में शामिल होगा।
  2. गलत directory में git add . इस्तेमाल करना, ताकि उस folder के बाहर की files stage न हों।
  3. .gitignore न होने की वजह से node_modules या .env जैसी files git add . से add करना।

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.