실수로 master 브랜치에 뭔가 커밋을하는 것을 멈추고 싶습니다. 그래서이 스크립트를 사용하여 어떤 브랜치인지 확인했지만 문제가 있습니다. 새 브랜치를 만들 때 이름 브랜치는 다른 브랜치에 있지만 마스터를 반환합니다.git hook pre-commit을 사용하여 master에게 커밋을 중지하는 방법
$ git branch
ignore
master
* set_support
$ git name-rev --name-only HEAD
master
이것은 내 스크립트입니다.
#!/bin/sh
# Check to see if we are on master branch. Stop accidental commits
if [ "`git name-rev --name-only HEAD`" == "master" ]
then
if [ -f i_want_to_commit_to_master ]
then
rm i_want_to_commit_to_master
exit 0
else
echo "Cannot commit to master branch Adrian"
echo "Remember to create file 'touch i_want_to_commit_to_master' to commit to master"
fi
exit 1
fi
exit 0
마크 : 최신 안정 태그와 동일한 결과에 대해 git를 다시 작성했습니다. 새 분기를 완결 한 후에 만 작동합니다.
$ mkdir gittest
$ cd gittest
$ git init
Initialized empty Git repository in /home/adrian/gittest/.git/
$ touch file1
$ git add file1
$ git commit
[master (root-commit) 7c56424] New file
0 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 file1
$ git branch
* master
$ git checkout -b new_branch
Switched to a new branch 'new_branch'
$ git name-rev --name-only HEAD
master
$ git --version
git version 1.7.7.1
$ git branch
master
* new_branch
$ touch file2
$ git add file2
$ git commit
[new_branch 1e038fb] new file
0 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 file2
$ git name-rev --name-only HEAD
new_branch
사용중인 git의 버전 및 운영 체제는 무엇입니까? 'git branch'의 결과와'git name-rev HEAD '의 결과는 정확하게 복사하고 정확하게 붙인 경우 (놀라운 버그)처럼 보입니다. –
나는 소스에서 자식을 구축 - 지난 빌드가 $의 자식이 2.6.40.3-0.fc15 iceweasel.bluedreamer v1.7.7-RC3 $ 자식 --version 자식 버전 1.7.7-RC3 $ 끝나면 uname -a 리눅스를 설명했다 .x86_64 # 1 SMP Tue Aug 16 04:10:59 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux –