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

Git New Files

आपके बनाए नए files automatically एक Git repository का हिस्सा नहीं बनते -- वे untracked की तरह शुरू होते हैं, और git status व git add वह तरीके हैं जिनसे आप Git को उन्हें follow और stage करना शुरू करने के लिए बताते हैं।
Syntax
bash
git status
git add new_file_name
git add file1 file2

Untracked Files और git status

एक newly created file जिसके बारे में Git को कभी नहीं बताया गया untracked कहलाती है -- git status इसे modified tracked files से अलग, इसके अपने 'Untracked files' heading के तहत list करता है, ताकि आप exactly देख सकें कि disk पर क्या exist करता है लेकिन अभी repository की history का हिस्सा नहीं है।

उदाहरण: Untracked Files and git status

bash
git status

एक Single नई File Add करना

एक file path के बाद git add चलाना उस single file को untracked या modified state से staging area में move कर देता है, इसे अगली commit में शामिल होने के लिए mark करते हुए बिना इस समय untracked या modified किसी दूसरी file को affect किए।

उदाहरण: Adding a Single New File

bash
git add index.html

कई नई Files Add करना

एक command में spaces से separated git add के बाद कई file paths list किए जा सकते हैं, या *.css जैसे shell wildcard से match किए जा सकते हैं, जो हर file के लिए एक अलग git add command की माँग करने के बजाय एक साथ pattern से match करने वाली हर file stage कर देता है।

उदाहरण: Adding Multiple New Files

bash
git add file1.txt file2.txt
git add *.css

git add . से सभी नई Files Add करना

git add . current directory और इसकी सभी subdirectories में मिली हर नई और modified file stage करता है, जबकि git add -A आगे जाकर deletions सहित पूरी repository stage करता है, चाहे command किसी भी directory से चलाया जाए।

उदाहरण: Adding All New Files with git add .

bash
git add .
git add -A

यह Check करना कि क्या Commit होगा

Commit करने से पहले, git status summarize करता है कि कौन सी files staged हैं और कौन सी अभी भी untracked या modified हैं, और git diff --cached exact line-by-line content दिखाता है जो staged किया गया है, आपको precisely confirm करने देते हुए कि अगली commit में क्या record होगा।

उदाहरण: Checking What Will Be Committed

bash
git status
git diff --cached
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. एक file बनाने के तुरंत बाद git commit चलाना, जबकि एक नई file untracked है और पहले git add चाहिए।
  2. git add *.txt इस्तेमाल करना और subfolders में files की उम्मीद करना, जबकि shell pattern सिर्फ current directory से match करता है जब तक git add '*.txt' जैसे quoted न हो।
  3. एक ऐसी file add करना जो .gitignore में पहले से list है, ताकि Git एक message के साथ मना कर दे जब तक आप -f इस्तेमाल न करें।

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.