確かに私が間違ってマスターブランチに何かをコミットしないようにしたいと思います。だから、私はこのブランチを試してみたが、問題がある。私が新しいブランチを作成すると、他のブランチ上にあっても名前revがマスターを返します。git hook pre-commitを使用してマスタへのコミットを停止する方法
$ 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'の結果は、実際に正確にコピーして貼り付けた場合、(驚くべき)バグのように見えます。 –
私はソースからのgitを構築する - 最後のビルドは、$ gitのは v1.7.7-RC3 $ gitの--version gitのバージョン1.7.7-RC3 $のuname -a のLinux iceweasel.bluedreamer 2.6.40.3-0.fc15を説明しました.x86_64#1 SMP Tue Aug 16 04:10:59 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux –