Git sadece sizin için ne yapmaya çalıştığınızı tahmin etmeye çalışıyor. Kesintisiz tarihi korumak için her türlü çabayı göstermektedir. Tabii ki, mükemmel değil. Böylece git mvniyetinizi açıkça belirtmenize ve bazı hatalardan kaçınmanıza izin verir.
Bu örneği ele alalım. Boş bir repo ile başlayarak,
git init
echo "First" >a
echo "Second" >b
git add *
git commit -m "initial commit"
mv a c
mv b a
git status
Sonuç:
# On branch master
# Changes not staged for commit:
# (use "git add/rm <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: a
# deleted: b
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# c
no changes added to commit (use "git add" and/or "git commit -a")
Otomatik algılama başarısız oldu :( Yoksa mı?
$ git add *
$ git commit -m "change"
$ git log c
commit 0c5425be1121c20cc45df04734398dfbac689c39
Author: Sergey Orshanskiy <*****@gmail.com>
Date: Sat Oct 12 00:24:56 2013 -0400
change
ve sonra
$ git log --follow c
Author: Sergey Orshanskiy <*****@gmail.com>
Date: Sat Oct 12 00:24:56 2013 -0400
change
commit 50c2a4604a27be2a1f4b95399d5e0f96c3dbf70a
Author: Sergey Orshanskiy <*****@gmail.com>
Date: Sat Oct 12 00:24:45 2013 -0400
initial commit
Şimdi bunun yerine deneyin (denerken .gitklasörü silmeyi unutmayın ):
git init
echo "First" >a
echo "Second" >b
git add *
git commit -m "initial commit"
git mv a c
git status
Çok uzak çok iyi:
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# renamed: a -> c
git mv b a
git status
Şimdi kimse mükemmel değil:
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: a
# deleted: b
# new file: c
#
Gerçekten mi? Ama tabii...
git add *
git commit -m "change"
git log c
git log --follow c
... ve sonuç yukarıdakiyle aynıdır: yalnızca --followtam geçmişi gösterir.
Her iki seçenek de tuhaf efektler üretebileceğinden , şimdi yeniden adlandırmaya dikkat edin . Misal:
git init
echo "First" >a
git add a
git commit -m "initial a"
echo "Second" >b
git add b
git commit -m "initial b"
git mv a c
git commit -m "first move"
git mv b a
git commit -m "second move"
git log --follow a
commit 81b80f5690deec1864ebff294f875980216a059d
Author: Sergey Orshanskiy <*****@gmail.com>
Date: Sat Oct 12 00:35:58 2013 -0400
second move
commit f284fba9dc8455295b1abdaae9cc6ee941b66e7f
Author: Sergey Orshanskiy <*****@gmail.com>
Date: Sat Oct 12 00:34:54 2013 -0400
initial b
Kontrast ile:
git init
echo "First" >a
git add a
git commit -m "initial a"
echo "Second" >b
git add b
git commit -m "initial b"
git mv a c
git mv b a
git commit -m "both moves at the same time"
git log --follow a
Sonuç:
commit 84bf29b01f32ea6b746857e0d8401654c4413ecd
Author: Sergey Orshanskiy <*****@gmail.com>
Date: Sat Oct 12 00:37:13 2013 -0400
both moves at the same time
commit ec0de3c5358758ffda462913f6e6294731400455
Author: Sergey Orshanskiy <*****@gmail.com>
Date: Sat Oct 12 00:36:52 2013 -0400
initial a
Ups ... Şimdi tarih, ilk b yerine ilk a'ya geri dönüyor , bu yanlış. Bir seferde iki hamle yaptığımızda Git'in kafası karıştı ve değişiklikleri düzgün bir şekilde takip etmedi. Bu arada, deneylerimde aynı şey dosyaları kullanmak yerine sildiğim / oluşturduğumda oldu . Dikkatle ilerleyin; uyarılmıştın...git mv