私はREADME.mdファイルの文字列パターンを見つけるためにGIT pre-commit
フックを使用しています。ex。 {{STRING_PATTERN}}を編集し、文字列パターンを現在のブランチ名も含む希望のテキスト/コード出力に変更します。GITプリコミットフックの変更ファイルがコミットに追加されない
ここが問題です。 pre-commit
スクリプトは、文字列パターンを見つけて正しいテキスト/コードに置き換えるという立場から働きますが、変更をコミットする前にこれを行うようには見えません。つまり、git commit -m "Updated README.md"
を実行してgit status
チェックREADME.mdファイルは変更されていると表示され、実行する場合はgit push origin branch_name
README.mdファイルには実際の{{STRING_PATTERN}}識別子(望ましくない)が含まれています。欲しい)。それだけではない - 私はこれはそれが文字列{{がstring_pattern}}識別子と、動的に作成されたテキスト/コードを使用してアップデートを見つけ観点から作業を行うことに注意してください、言ったようにここで
は、pre-commit
コードです実際にそれらの変更をコミットすることが問題です。
#!/usr/bin/env bash
# Echo out text to ensure pre-commit is running
echo "pre-commit working"
# Get the current branch name
function git_branch {
git rev-parse --abbrev-ref HEAD
}
# Set branch variable to current branch
branch=$(git_branch)
# Define the string/pattern marker to search for
# This pattern/string serves as a marker that
# gets replaced with the dynamically created text/code
id="{{STRING_PATTERN}}"
# Dynamically create text/code
# Inject the $branch variable into the correct location of the text
updated_text="Example text containing that is being added to the $branch branch"
# Find the string/pattern and replace it with the text/code
# Then replace it with the build status image
sed -i '' -e "s%{{STRING_PATTERN}}%$updated_text%g" README.md
あなたが 'git add'を追加すると、それはスクリプトの最後に追加されるべきことを意味しますか?それで 'sed'コードブロックを実行した後は?また、 'git commit'を再実行する必要があることを意味しませんか? – corey
はい、まさに、スクリプトの最後に 'git add'があります –