Sürekli https://stackoverflow.com/a/20574486/4935114 , @ Mike bir oluşturmak için önerilen pre-commitolacak kanca grepkimsenin görmezden isteyebilirsiniz hatları için dosyaları sahnelenen içinde. Kanca, bu satırların aşamalı olup olmadığını kontrol eder. Eğer öyleyse, bu bir echouyarıdır ve exitkod içerir, 1bu yüzden commit işlemi devam etmez.
@ Mike'ın cevabından esinlenerek , kendimi belki de görmezden gelmek istediğimiz belirli bir çizgiyi otomatik olarak reset ( -pbayrakla birlikte) kullanan kancasının geliştirilmiş bir versiyonunu kullanırken buldum .
Bu kancanın, bu satırda göz ardı edilecek birçok dosyanızın olduğu bir durumda işe yarayacağından emin değilim, ancak bu pre-commitkanca belirli bir dosyada bu satırda bir değişiklik arar buildVars.java. Kanca betiği makinemde test ettiğimde böyle görünüyordu.
#!/bin/sh
# this hook looks for lines with the text `var isPhoneGap = false;` in the file `buildVars.java` and it resets these lines to the previous state before staged with `reset -p`
if [[ $(git diff --no-ext-diff --cached buildVars.java | grep --count -e "var\ isPhoneGap[\ ]*=[\ ]*") -ne 0 ]]; then
cat <<EOW
WARNING: You are attempting to commit changes which are not supposed to be commited according to this \`pre-commit\` hook
This \`pre-commit\` hook will reset all the files containing this line to it's previous state in the last commit.
EOW
echo /$'\n'isPhoneGap$'\n'y$'\n'q | git reset -p
# BONUS: Check if after reseting, there is no actual changes to be commited and if so, exit 1 so the commit process will abort.
if [[ $(git diff --no-ext-diff --cached | wc -l) -eq 0 ]]; then
echo there are no actual changes to be commited and besides the change to the variable \'isPhoneGap\' so I won\'t commit.
exit 1
fi
fi
açıklama
Yaptığım şey, isPhoneGapetkileşimli bir resetişlem sırasında normal ifadeyi arayan bir kontrol dizilerini tekrarlamaktı . Böylece /, aramak için baskı yapan bir kullanıcıyı taklit eder isPhoneGap, ybu yamayı iptal etmek isteyip istemediği sorulduğunda basar ve sonunda qinteraktiften çıkmak için basar reset.
Etkileşimli ters yama işlemi burada belgelenmiştir: https://git-scm.com/docs/git-add#git-add-patch
NOT: Değişkenin interactive.singleKeyolduğunu varsayan yukarıdaki komut dosyası false. Size seninkini yapılandırılmış ise true, herhangi kaldırmak $'\n'gelen echosağ uyarıdan sonra komuta.