Skip to content

Instantly share code, notes, and snippets.

@cemtopkaya
Last active September 2, 2025 18:19
Show Gist options
  • Select an option

  • Save cemtopkaya/24c42c6c31755ccfd1bd9c00985e77a7 to your computer and use it in GitHub Desktop.

Select an option

Save cemtopkaya/24c42c6c31755ccfd1bd9c00985e77a7 to your computer and use it in GitHub Desktop.
Etiketlerin öncülünü bulmak için örnek
/bin/bash
cd /Users/cemt/projects/cop/git-tag
alias ll="ls -al --color"
rm -rf myrepo master_1
git config --global init.defaultBranch master


# 1. Adım: repo hazırlığı
git init myrepo
cd myrepo

# master_1 dosyası
echo "master v1" > master_1
git add master_1
git commit -m "Initial commit"

# Etiket
git tag 1.0.0

# 2. Adım: feature/1 dalı ve 3 commit
git checkout -b feature/1

echo "f1.1" > feature_1_1
git add .
git commit -m "feature/1 step 1"

echo "f1.2" > feature_1_2
git add .
git commit -m "feature/1 step 2"

echo "f1.3" > feature_1_3
git add .
git commit -m "feature/1 step 3"


# 3. Adım: 1.1.0 etiketi ve master’a birleşme (branch silinmeyecek)
git tag 1.1.0
git checkout master
git merge --no-ff feature/1 -m "Merge feature/1 into master"


# 4. Adım: feature/2 dalı ve 2 commit
git checkout -b feature/2

echo "f2.1" > feature_2_1
git add .
git commit -m "feature/2 step 1"

echo "f2.2" > feature_2_2
git add .
git commit -m "feature/2 step 2"

# 1.2.0 etiketi şimdilik feature/2 üzerinde olacak:
git tag 1.2.0


# 5. Adım: başka geliştirici bugfix/1 dalı açıyor
git checkout master
git checkout -b bugfix/1

echo "bug1" > bugfix_1_1
git add .
git commit -m "bugfix/1 step 1"

echo "bug2" > bugfix_1_2
git add .
git commit -m "bugfix/1 step 2"

git tag 1.1.1

feature/2 -> master & bugfix/1 -> master

# 6. Adım: feature/2 → master birleşmesi
git checkout master
git merge --no-ff feature/2 -m "Merge feature/2 into master"

# 7. Adım: bugfix/1 → master birleşmesi
git merge --no-ff bugfix/1 -m "Merge bugfix/1 into master"

Uzun ömürlü product/2 ve 3 dalları ve etiketleri başlıyor

# 8. Adım: product/2 dalı açılış ve 2.0.0 etiketi
git checkout master
git checkout -b product/2

git tag 2.0.0

# 9. Adım: 3 commit ve 2.0.1 etiketi
echo "p2.1" > product2_1
git add .
git commit -m "product/2 step 1"

echo "p2.2" > product2_2
git add .
git commit -m "product/2 step 2"

echo "p2.3" > product2_3
git add .
git commit -m "product/2 step 3"

git tag 2.0.1


# 10. Adım: 2 commit ve 2.0.2 etiketi
echo "p2.4" > product2_4
git add .
git commit -m "product/2 step 4"

echo "p2.5" > product2_5
git add .
git commit -m "product/2 step 5"

git tag 2.0.2

# 11. Adım: product/3 dalı açılış ve 3.0.0 etiketi
git checkout master
git checkout -b product/3

git tag 3.0.0


# 12. Adım: 3 commit ve 3.0.1 etiketi
echo "p3.1" > product3_1
git add .
git commit -m "product/3 step 1"

echo "p3.2" > product3_2
git add .
git commit -m "product/3 step 2"

echo "p3.3" > product3_3
git add .
git commit -m "product/3 step 3"

git tag 3.0.1

# 13. Adım: 2 commit ve 3.0.2 etiketi
echo "p3.4" > product3_4
git add .
git commit -m "product/3 step 4"

echo "p3.5" > product3_5
git add .
git commit -m "product/3 step 5"

git tag 3.0.2

master -> bugfix/2

# 1. Adım: bugfix/2 dalını aç
git checkout master
git checkout -b bugfix/2

# 2. Adım: 3 commit yap
echo "fix a" > bugfix2_1
git add .
git commit -m "bugfix/2 step 1"

echo "fix b" > bugfix2_2
git add .
git commit -m "bugfix/2 step 2"

echo "fix c" > bugfix2_3
git add .
git commit -m "bugfix/2 step 3"

git tag 1.1.2

Etiketleri listele ve öncül, ardıl ilişkisiyle sırasını bul:

# Sonuç
git describe --tags 1.2.0

# veya
git tag --sort=creatordate

# veya
git describe --tags --abbrev=0 1.1.2^
bash-3.2$ git log  --graph --oneline  --all
* 3f3d7a4 (HEAD -> bugfix/2, tag: 1.1.2) bugfix/2 step 3
* f8edd75 bugfix/2 step 2
* ba97143 bugfix/2 step 1
| * cfd7c0e (tag: 2.0.2, product/2) product/2 step 5
| * 26075fd product/2 step 4
| * 9e13023 (tag: 2.0.1) product/2 step 3
| * e74aedc product/2 step 2
| * 91c54b5 product/2 step 1
|/
| * bca2763 (tag: 3.0.2, product/3) product/3 step 5
| * 0303afd product/3 step 4
| * 1861fb6 (tag: 3.0.1) product/3 step 3
| * f33afb3 product/3 step 2
| * e0d01ad product/3 step 1
|/
*   014a31d (tag: 3.0.0, tag: 2.0.0, master) Merge bugfix/1 into master
|\
| * 07d9e0a (tag: 1.1.1, bugfix/1) bugfix/1 step 2
| * 8f8af56 bugfix/1 step 1
* |   f7b2a68 Merge feature/2 into master
|\ \
| |/
|/|
| * 5cc1e1f (tag: 1.2.0, feature/2) feature/2 step 2
| * 80002bd feature/2 step 1
|/
*   185a95b Merge feature/1 into master
|\
| * b28c1a8 (tag: 1.1.0, feature/1) feature/1 step 3
| * e3bd5ce feature/1 step 2
| * 4818612 feature/1 step 1
|/
* c621a11 (tag: 1.0.0) Initial commit
bash-3.2$ git describe --tags --abbrev=0 1.1.2^
2.0.0
bash-3.2$ git describe --tags --abbrev=0 2.0.2^
2.0.1
bash-3.2$ git describe --tags --abbrev=0 2.0.1^
2.0.0
bash-3.2$ git describe --tags --abbrev=0 2.0.0^
1.1.0
bash-3.2$ git describe --tags --abbrev=0 1.1.1^
1.1.0
bash-3.2$ git describe --tags --abbrev=0 1.1.0^
1.0.0
bash-3.2$ git describe --tags --abbrev=0 1.2.0^
1.1.0
bash-3.2$ git describe --tags --abbrev=0 1.1.1^
1.1.0
bash-3.2$ git log --simplify-by-decoration  --graph --oneline  --all
* 3f3d7a4 (HEAD -> bugfix/2, tag: 1.1.2) bugfix/2 step 3
| * cfd7c0e (tag: 2.0.2, product/2) product/2 step 5
| * 9e13023 (tag: 2.0.1) product/2 step 3
|/  
| * bca2763 (tag: 3.0.2, product/3) product/3 step 5
| * 1861fb6 (tag: 3.0.1) product/3 step 3
|/  
*   014a31d (tag: 3.0.0, tag: 2.0.0, master) Merge bugfix/1 into master
|\  
| * 07d9e0a (tag: 1.1.1, bugfix/1) bugfix/1 step 2
* | 5cc1e1f (tag: 1.2.0, feature/2) feature/2 step 2
|/  
* b28c1a8 (tag: 1.1.0, feature/1) feature/1 step 3
* c621a11 (tag: 1.0.0) Initial commit
cd /Users/cemt/projects/cop/git-tag
rm -rf example-repo

# 1. Yeni boş repo oluştur
git init example-repo
cd example-repo

# 2. İlk commit
echo "ilk satir" > file.txt
git add file.txt
git commit -m "Başlangıç commit'i"

# 3. İkinci commit
echo "ikinci satir" >> file.txt
git commit -am "Önceki sürüm hazırlanıyor"

# 4. Üçüncü commit
echo "üçüncü satir" >> file.txt
git commit -am "Son küçük hata düzeltmeleri"

# 5. Dördüncü commit - Annotated tag işaretlenecek commit olacak
echo "yeni özellik" >> file.txt
git commit -am "Yeni özellik eklendi"

# 6. Beşinci commit - Annotated tag burada olacak
echo "sürüm 1.0" >> file.txt
git commit -am "Sürüm 1.0 yayınlandı"
git tag -a v1.0 -m "v1.0 annotated etiketi" HEAD~4
git tag v2.0-lw

# 7. Log çıktısını görmek için
git log --oneline --decorate --graph

Etiket yaratılacağı yerden 4 commit öncesini işaret edecek git tag -a v1.0 -m "v1.0 annotated etiketi" HEAD~4

$ git log --oneline --decorate --graph
* ecc2511 (HEAD -> master, tag: v2.0-lw) Sürüm 1.0 yayınlandı
* d7f8ff8 Yeni özellik eklendi
* bd8d9ee Son küçük hata düzeltmeleri
* ad2271f Önceki sürüm hazırlanıyor
* ac44b86 (tag: v1.0) Başlangıç commit'i

Annotated etiket olacağı için kendisi bir nesne, işaret ettiği commit başka bir nesne olacak:

$ git show v1.0
tag v1.0
Tagger: Cem Topkaya <[email protected]>
Date:   Tue Sep 2 21:11:48 2025 +0300

v1.0 annotated etiketi

commit ac44b863ecafc387fa4d2152c081667382a69d67 (tag: v1.0)
Author: Cem Topkaya <[email protected]>
Date:   Tue Sep 2 21:11:48 2025 +0300

    Başlangıç commit'i

diff --git a/file.txt b/file.txt
new file mode 100644
index 0000000..c9a4a5e
--- /dev/null
+++ b/file.txt
@@ -0,0 +1 @@
+ilk satir

Lightweight Tag:

$ git show v2.0-lw
commit ecc25117e9a447aad5ed635126cb3e140d541f6e (HEAD -> master, tag: v2.0-lw)
Author: Cem Topkaya <[email protected]>
Date:   Tue Sep 2 21:11:48 2025 +0300

    Sürüm 1.0 yayınlandı

diff --git a/file.txt b/file.txt
index b3232a1..fa0a2d2 100644
--- a/file.txt
+++ b/file.txt
@@ -2,3 +2,4 @@ ilk satir
 ikinci satir
 üçüncü satir
 yeni özellik
+sürüm 1.0
$ git show-ref v1.0
e33773e7a7617f788c492273cec0b3a7956b4a66 refs/tags/v1.0
$ git rev-parse v1.0
e33773e7a7617f788c492273cec0b3a7956b4a66


# İşaret ettiği commit 
$ git rev-list -n 1 v1.0
ac44b863ecafc387fa4d2152c081667382a69d67

Lightweight etiketin kendisi ve işaret ettiği SHA doğrudan commit'in ID değeri:

$ git show-ref v2.0-lw
ecc25117e9a447aad5ed635126cb3e140d541f6e refs/tags/v2.0-lw
$ git rev-parse v2.0-lw
ecc25117e9a447aad5ed635126cb3e140d541f6e

# İşaret ettiği commit 
$ git rev-list -n 1 v2.0-lw
ecc25117e9a447aad5ed635126cb3e140d541f6e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment