每次提交后,git 文件 COMMIT_EDITMSG 都设置为只读

每次提交后,git 文件 COMMIT_EDITMSG 都设置为只读

我在 Windows 7 上使用 git(我的用户在本地管理员组中)处理我的开发项目,但每次我提交更改时,文件.git/COMMIT_EDITMSG也会更改:它的内容会被最后的提交消息替换(这很好),它的属性更改为readonly

由于此属性的改变,我下次提交时将返回错误“权限被拒绝”...

正如我在其他帖子中看到的,我尝试删除这两个文件:- .git/COMMIT_EDITMSG -.git/COMMIT_EDITMSG.bak

或者我也尝试过手动取消选中该readonly属性,但下次成功提交后问题仍然存在......

我该怎么做才能修复这个问题?

请注意,我设置了一个prepare-commit-msg可能是问题所在钩子?钩子内容如下:

#!/bin/bash

# Name this script "prepare-commit-msg"
# This script will prefix every commit msg with the branch name in brackets,
# except if we are on non working branch like develop or master.
# The branch name pattern is : {category}/{issue-nb}_{work-description}

if [ -z "$BRANCHES_TO_SKIP" ]; then
  BRANCHES_TO_SKIP=(master develop)
fi

# Find current branch name
BRANCH_NAME=$(git symbolic-ref --short HEAD)
# Remove category before slash (included)
BRANCH_NAME="${BRANCH_NAME##*/}"
# Remove description after first underscore (included)
BRANCH_NAME="${BRANCH_NAME%_*}"


# Check if the branch is excluded
BRANCH_EXCLUDED=$(printf "%s\n" "${BRANCHES_TO_SKIP[@]}" | grep -c "^$BRANCH_NAME$")
BRANCH_IN_COMMIT=$(grep -c "\[$BRANCH_NAME\]" $1)

# Check if branch name is not null, if the current branch is not an excluded one, and if the branch name is already in the commit msg
if [ -n "$BRANCH_NAME" ] && ! [[ $BRANCH_EXCLUDED -eq 1 ]] && ! [[ $BRANCH_IN_COMMIT -ge 1 ]]; then 
  # Add brackets around branch name and Prefix passed msg with it
  sed -i.bak -e "1s/^/[$BRANCH_NAME] /" $1
fi

相关内容