Skip to content

Instantly share code, notes, and snippets.

@zhaopan
Last active March 1, 2023 09:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zhaopan/0699b9a2c6af52074a172eb765629025 to your computer and use it in GitHub Desktop.
Save zhaopan/0699b9a2c6af52074a172eb765629025 to your computer and use it in GitHub Desktop.
# git 重命名文件夹/文件
git mv -f <oldfolder> <newfolder>

# eg: 现有文件夹:test,需修改为:test_file
git mv -f test test_file
git add -u test_file    # -u:会更新已经追踪的文件和文件夹
git commit -m "重命名文件夹"
git push origin master
#!/bin/bash
# 将文件置于.git/hooks/下, 去掉.sh后缀,并修改权限为755
msg=$(head -n 1 $1)
if echo $msg | grep -iqE "^Merge "; then
exit 0
fi;
if echo $msg | grep -iqE "^Revert "; then
exit 0
fi;
if echo $msg | grep -iqE "^\d{1,2}[.]\d{1,2}[.]\d{1,2}$"; then
exit 0
fi;
if echo $msg | grep -iqE "^(feat|fix|docs|style|refactor|perf|test|chore|ci)(\([^()]{1,}\)){0,1}: [a-z].*"; then
exit 0
fi;
echo
echo -e "\033[41mINVALID COMMIT MSG:\033[0m Does not match \"<type>(<scope>): <subject>\" !"
echo
cat <<EOF
Available types and what it mean are list here
feat: A new feature
fix: A bug fix
docs: Documentation only changes
style: Changes that do not affect the meaning of the code
(white-space, formatting, missing semi-colons, etc)
refactor: A code change that neither fixes a bug or adds a feature
perf: A code change that improves performance
test: Adding missing tests
chore: Changes to the build process or auxiliary tools
and libraries such as documentation generation
ci: Changes to our CI configuration files and scripts
(example scopes: Travis, Circle, BrowserStack, SauceLabs)
EOF
echo -e "Please read https://github.com/zhaopan/pub/blob/master/06.git/02.git.commit.md"
echo
exit 1
#!/bin/bash
while read line
do
oldrev=$(echo $line | awk '{print $1}')
newrev=$(echo $line | awk '{print $2}')
done
revs=$(git rev-list ${oldrev}..${newrev})
for rev in $revs
do
msg=$(git log -1 --format="%s" $rev)
if echo $msg | grep -iqE "^Merge "; then
continue
fi;
if echo $msg | grep -iqE "^Merge "; then
continue
fi;
if echo $msg | grep -iqE "^\d{1,2}[.]\d{1,2}[.]\d{1,2}$"; then
continue
fi;
if echo $msg | grep -qE "^(feat|fix|docs|style|refactor|perf|test|chore|ci)(\([^()]{1,}\)){0,1}: [a-z].*"; then
continue
fi;
echo
echo -e "INVALID COMMIT MSG: "${msg}" Does not match \"<type>(<scope>): <subject>\" !"
echo
cat <<EOF
Available types and what it mean are list here
feat: A new feature
fix: A bug fix
docs: Documentation only changes
style: Changes that do not affect the meaning of the code
(white-space, formatting, missing semi-colons, etc)
refactor: A code change that neither fixes a bug or adds a feature
perf: A code change that improves performance
test: Adding missing tests
chore: Changes to the build process or auxiliary tools
and libraries such as documentation generation
ci: Changes to our CI configuration files and scripts
(example scopes: Travis, Circle, BrowserStack, SauceLabs)
EOF
echo -e "Please read https://github.com/zhaopan/pub/blob/master/06.git/02.git.commit.md"
echo
exit 1
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment