git post-update script does not work

后端 未结 3 1630
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-06 08:52

After editing my old question a few times, I make a new one because it is a new question now.

In .git/hooks/post-update I have:

echo \"a         


        
相关标签:
3条回答
  • 2021-01-06 09:30

    EDIT

    It looks like this is your problem:

     pre-receive
     update
     post-receive
     post-update
    

    These hooks can be run either in a bare or a non-bare repository. In both cases, the current working directory will be the git directory. So, if this is a bare repository called "/src/git/test.git/", that will be the current working directory -- if this is a non-bare repository and the top level of the working tree is "/home/mark/test/" then the current working directory will be "/home/mark/test/.git/".

    In both cases, the following environment variable is set: GIT_DIR is set to ‘.’

    With a working tree, this is unexpectedly awkward, as described in Chris Johnsen’s answer that I linked to earlier. If only GIT_DIR is set then this comment from the git man page applies:

    Note: If --git-dir or GIT_DIR are specified but none of --work-tree, GIT_WORK_TREE and core.worktree is specified, the current working directory is regarded as the top directory of your working tree.

    In other words, your working tree will also be the current directory (the ".git" directory), which almost certainly isn’t what you want.

    You could try setting GIT_WORK_TREE=.. or GIT_WORK_TREE="$GIT_DIR/.." inside the hook


    But the file did not change!

    Most likely it did. Perhaps only the lineending did, or there were whitespace changes that are ignored when viewing the diffs, but it did change. Git knows, because the SHA1 sum of the file content changed.

    Are you using windows on either end?

    Windows has a tendency to mess with the line-endings. See the core.autocrlf and related options:

    • Why should I use core.autocrlf=true in Git?
    0 讨论(0)
  • 2021-01-06 09:36

    Did you try to use the post-receive hook instead? Maybe something is not yet finished in the post-update and that is why the merge is not working.

    Also I think you should try to include git reset --hard in the script so that the git status is synchronised with the file system.

    0 讨论(0)
  • 2021-01-06 09:41

    The solution is to use post-receive as Alex pointed out. Also you need run unset GIT_DIR at the top of your script.

    On the server I have created a second branch and switched to it:

    $ git branch
      master
    * testing
    

    My .git/hooks/post-receive now looks like this:

    unset GIT_DIR
    cd ..
    git merge master
    

    On the client I run git push.

    0 讨论(0)
提交回复
热议问题