alın son 20 kaydedilmesini: Sonra yineleme
declare -A COMMITS # Declare associative array
COMMITNUMBER=0
while read -r line; do # For each line, do
# Add 1 to COMMITNUMBER, if the current line contains "commit [0-9a-f]* (e.g., new associative array index for each commit)
# As this'll happen straight way, our array is technically 1-indexed (starts from "${COMMITS[1]}", not "${COMMITS[0]}")
REGEX="commit\s[0-9a-f]*"
[[ "$line" =~ $REGEX ]] && COMMITNUMBER=$((COMMITNUMBER+1))
# Append the commit line to the index
COMMITS[$COMMITNUMBER]="${COMMITS[$COMMITNUMBER]} $line"
done < <(git log -n 20)
:
git log -n 20
bir ilişkisel dizi her Get
for i in "${!COMMITS[@]}"
do
echo "key : $i"
echo "value: ${COMMITS[$i]}"
done
Bu aşağıda benzer bir çıktı verir:
key : 1
value: commit 778f88ec8ad4f454aa5085cd0c8d51441668207c Author: Nick <[email protected]> Date: Sun Aug 7 11:43:24 2016 +0100 Second commit
key : 2
value: commit a38cd7b2310038af180a548c03b086717d205a61 Author: Nick <[email protected]> Date: Sun Aug 7 11:25:31 2016 +0100 Some commit
Şimdi grep
ya da bir şey kullanarak döngü içinde her arama ve neye ihtiyacınız eşleşebilir: Toplamda
for i in "${!COMMITS[@]}"
do
REGEX="Date:[\s]*Sun\sAug\7"
if [[ "${COMMITS[$i]}" =~ $REGEX ]]; then
echo "The following commit matched '$REGEX':"
echo "${COMMITS[$i]}"
fi
done
:
search_last_commits() {
[[ -z "$1" ]] && echo "Arg #1: No search pattern specified" && return 1
[[ -z "$2" ]] && echo "Arg #2: Number required for number of commits to return" && return 1
declare -A COMMITS # Declare associative array
COMMITNUMBER=0
while read -r line; do # For each line, do
# Add 1 to COMMITNUMBER, if the current line contains "commit [0-9a-f]* (e.g., new associative array index for each commit)
# As this'll happen straight way, our array is technically 1-indexed (starts from "${COMMITS[1]}", not "${COMMITS[0]}")
REGEX="commit\s[0-9a-f]*"
[[ "$line" =~ $REGEX ]] && COMMITNUMBER=$((COMMITNUMBER+1))
# Append the commit line to the index
COMMITS[$COMMITNUMBER]="${COMMITS[$COMMITNUMBER]} $line"
done < <(git log -n $2)
for i in "${!COMMITS[@]}"
do
REGEX="$1"
if [[ "${COMMITS[$i]}" =~ $REGEX ]]; then
echo "The following commit matched '$REGEX':"
echo "${COMMITS[$i]}"
fi
done
}
EDIT:
Kullanımı:
search_last_commits <search-term> <last-commits-quantity>
Örnek:
search_last_commits "Aug" 20
İşlemi çeşitlendirmek için git diff' gibi bir şey hayal ediyorum, daha sonra 'grep' –
'ya pipetle' git log -g --grep = TEXT'? – Shravan40
@ Shravan40 '--grep''i kaçırıyor musunuz? –