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

Git commit Command

git commit आपकी चुनी हर चीज़ का एक snapshot लेकर एक छोटे caption के साथ एक photo album में paste करने जैसा है। बाद में आप कभी भी वापस flip कर सकते हैं।
Syntax
bash
git commit -m "commit message"
git commit -am "commit message"
git commit --amend

एक Message के साथ Commit करना

git commit -m "message" इस समय staged हर चीज़ को आपके project की history में एक नए permanent snapshot की तरह save करता है। message कोई optional busywork नहीं है -- क्या बदला इसका एक specific, honest description महीनों बाद git log को उपयोगी बनाता है।

उदाहरण: Committing with a Message

bash
git commit -m "Fix login button alignment"

एक Step में Staging और Committing

git commit -am "message" Git पहले से track की गई files के लिए staging और committing combine करता है, अलग git add step skip करते हुए -- लेकिन ध्यान दें shortcut सिर्फ tracked files में modifications पकड़ता है, यह कभी आपके लिए एक बिल्कुल नई untracked file stage नहीं करेगा।

उदाहरण: Staging and Committing in One Step

bash
git commit -am "Update styles"

Last Commit Amend करना

git commit --amend आपकी सबसे हाल की commit को पूरी तरह replace कर देता है -- एक corrected message, एक भूली हुई file add, या दोनों के साथ -- एक नई commit बनाने के बजाय। यह गलती को उसके seconds बाद fix करने के लिए convenient है, लेकिन पहले से push और shared की गई commit को amend करने से बचें।

उदाहरण: Amending the Last Commit

bash
git commit --amend

एक Detailed Description के साथ Commit करना

एक change के लिए जिसे एक line से ज़्यादा explanation चाहिए, git commit -m "Title" -m "Longer paragraph explaining why" चलाना एक छोटी summary line और एक अलग detailed body वाली एक commit बनाता है, ज़्यादातर Git tools की expected conventional format से match करते हुए।

उदाहरण: Committing with a Detailed Description

bash
git commit -m "Fix login bug" -m "The button was not responding on mobile Safari due to a missing touch event handler."

Empty Commits

git commit --allow-empty zero file changes वाली एक commit बनाता है, जो useless लगता है लेकिन एक CI/CD pipeline manually trigger करने के लिए, या बिना कोई code बदले history में एक meaningful milestone mark करने के लिए genuinely handy है।

उदाहरण: Empty Commits

bash
git commit --allow-empty -m "Trigger CI pipeline"
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. बिना -m के git commit चलाना और Vim जैसे एक editor में drop हो जाना, यह न जानते हुए कि कैसे save और exit करें।
  2. git commit -am इस्तेमाल करना और नई untracked files के शामिल होने की उम्मीद करना, जबकि -a सिर्फ Git की पहले से tracked files stage करता है।
  3. पहले से push की गई commit पर git commit --amend इस्तेमाल करना, जो history rewrite करता है और दूसरों को conflicts से deal करने पर मजबूर करता है।

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.