git commit --amend
. This is convenient for minor edits (change the comment to the commit, correct the line in the code, etc.), because quite often good thoughts about the commit come to mind after this commit has been made.--amend
option ends where the use of the git push
command begins.git push
), then in the future you will create problems for yourself (when you try to publish your edited commit) and ( most important! ) Create problems for other developers who managed to get your local repositories old commit In this case, both you and other developers are given the headache of clearing the commit history to correct the situation.git commit --amend
not so good and comfortable! She wants to use, not looking at the history of commits in the remote repository. Therefore, I had a desire to automate such checks..git/hooks
and are script files with predefined names corresponding to their functional purpose. For my task, a message sniffer is suitable for the prepare-commit-msg commit .git commit --amend
; #!/bin/bash case "$2,$3" in commit,HEAD) # short SHA-1 sha1_local=$(git branch -vv | \ perl -lne 'print "$1" if /\*{1}\s+\S+\s+(\w+)\s+\[(\S+)\/(\S+).*\]\s+.*/') # (remote branch) remote_branch=$(git branch -vv | \ perl -lne 'print "$1/$2" if /\*{1}\s+\S+\s+\w+\s+\[(\S+)\/(\S+).*\]\s+.*/') # short SHA-1 (remote branch) sha1_remote=$(git branch -rv | \ awk -v branch=$remote_branch '{ if ($1 == branch) print $2 }') if [ -n "$sha1_local" ] && [ -n "$sha1_remote" ] && [ "$sha1_local" = "$sha1_remote" ] then # , # - ci_comment=$(cat "$1" | grep -v '#' | perl -lne 'print "# $_"') ci_autogen=$(cat "$1" | grep '#') echo -e "$ci_comment" > "$1" # echo -e "# ! !\n" >> "$1" echo -e "$ci_autogen" >> "$1" fi ;; *) ;; esac
Source: https://habr.com/ru/post/221819/
All Articles