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

Git tags Command

एक tag photo album के एक page पर एक bright flag चिपकाकर कहने जैसा है 'यह version 1 है'। Flag हमेशा उस exact page पर रहता है और कभी move नहीं होता।
Syntax
bash
git tag tag_name
git tag -a tag_name -m "tag message"
git tag -l "pattern"

Lightweight Tags बनाना

एक lightweight tag बस एक specific commit की ओर एक named pointer है, अपना कोई extra metadata न रखते हुए — essentially एक branch जो कभी move नहीं होता। ये बनाना तेज़ है और private, temporary bookmarks के लिए fine हैं, लेकिन इनमें वह authorship और message info नहीं जो एक real release आमतौर पर चाहता है।

उदाहरण: Creating Lightweight Tags

bash
git tag v1.0

Annotated Tags बनाना

एक annotated tag (git tag -a v1.0 -m "message") Git के database में एक पूरे object की तरह stored है, tagger के name, email, date, और एक message सहित — वैसे ही जैसे एक commit। यह किसी भी चीज़ के लिए recommended tag type है जिसे आप actually एक release की तरह publish करेंगे, क्योंकि extra metadata document करता है कि release किसने और क्यों cut की।

उदाहरण: Creating Annotated Tags

bash
git tag -a v1.0 -m "Release version 1.0"

Tags List और Search करना

अकेले git tag repository की हर tag list करता है, और git tag -l "v1.*" उस list को एक glob pattern तक filter करता है — handy एक बार जब किसी project में दर्जनों version tags जमा हो जाएँ और आपको सिर्फ एक release line की परवाह हो।

उदाहरण: Listing and Searching Tags

bash
git tag
git tag -l "v1.*"

Project Tags Delete करना

git tag -d <name> एक tag locally delete करता है, लेकिन क्योंकि tags commits से अलग एक remote पर push होते हैं, इसे shared remote से हटाने के लिए आपको git push origin --delete <name> (या :refs/tags/<name>) भी चाहिए — नहीं तो यह अगली बार कोई fetch करने पर फिर दिख जाता है।

उदाहरण: Deleting Project Tags

bash
git tag -d v1.0
git push origin --delete v1.0

Remote Servers पर Tags Share करना

Commits और branches के उलट, git push default रूप से tags upload नहीं करता, इसलिए locally बनाया गया एक tag collaborators को तब तक invisible रहता है जब तक आप explicitly इसे git push origin <tagname> से push न करें या git push --tags से सभी tags एक साथ push करें।

उदाहरण: Sharing Tags on Remote Servers

bash
git push origin v1.0
git push origin --tags
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. एक tag बनाना और उसके remote पर होने की उम्मीद करना, जबकि git push tags नहीं भेजता और आपको git push origin v1.0 चाहिए।
  2. एक release के लिए एक lightweight tag इस्तेमाल करना जब आपको एक author, date और message चाहिए, जिसे -a वाला एक annotated tag चाहिए।
  3. गलत commit को tag करना क्योंकि आपने check नहीं किया कि कौन सी commit HEAD है, जबकि आप git tag v1.0 <hash> से एक specific को tag कर सकते हैं।

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.