Voglio fermarmi accidentalmente a dare qualcosa al master branch a meno che non ne sia sicuro. Così ho provato questo script per determinare quale ramo sono attivo, ma c'è un problema. Quando creo un nuovo ramo git rendimenti nome-rev maestro anche se io sono sull'altro ramoCome usare git hook pre-commit per fermare i commit al master
$ git branch
ignore
master
* set_support
$ git name-rev --name-only HEAD
master
Questo è il mio script.
#!/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
Per Mark: ho ricostruito git contro l'ultimo tag stabile e gli stessi risultati. Funziona solo dopo che viene effettuato un commit sul nuovo ramo.
$ 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
Quale versione di git stai usando e su quale sistema operativo? I risultati di 'git branch' seguiti da' git name-rev HEAD' sembrano un bug (sorprendente), se veramente copiato e incollato accuratamente. –
Costruisco git dalla fonte - ultima build era $ git descrivere v1.7.7-rc3 $ git --version git versione 1.7.7-RC3 $ uname -a Linux iceweasel.bluedreamer 2.6.40.3-0.fc15 .x86_64 # 1 SMP mar 16 ago 04:10:59 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux –