如何检入用git构建的文件? [英] How do I check in files for building with git?

查看:120
本文介绍了如何检入用git构建的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用git来管理我拥有的grails项目。我在远程服务器上建立了一个git仓库,我想要做的是当我有本地代码工作时,我想提交它并推送到远程服务器。我希望将更新后的groovy文件和gsp放到远程服务器上的正确位置,以便grails能够接受远程测试的更改。这可能吗?

解决方案

如果您推送到远程仓库,其中它似乎只包含一个大的文件包,没有实际的源代码(正如你在评论中详细说明的那样),这应该意味着裸回购,这对它有好处,它可以让你在没有任何工作树和git数据差异风险的情况下推送。

然后,按照我可以使用git让远程服务器保持最新吗?,另一个(非裸)回购和一个更新后的钩子在裸回购方将获得你想要的地方。






OP TripWired 补充道:


好的,我做的是:





  • 创建用于检入的裸回购

  • 我创建了另一个标准回购,基本上我有〜/ project.git 〜/ project

  • 我将 project.git 克隆到项目中, code> project.git / hooks / post-update 我把:



    cd ../../project
    env -i git结帐。
    env -i git pull





我也确保post-更新是可执行的。

当我从命令行运行钩子时它可以正常工作,但当我执行检查时,似乎无法正常工作。


我同意步骤1和2,但会使用此脚本,如此问题



检查它是否适用于从本地仓库到裸仓库的 git push

 #!/ bin / sh 

#这个钩子做了两件事:

#1。更新允许引用列表为
#查询的info文件,例如http

#2等非哑传输。如果此存储库看起来像一个非裸存储库,
#检出分支被推送到,然后更新工作c OPY。
#这使推功能有点类似于darcs和bzr。

#为了启用该钩子,可以通过chmod + x post-update使该文件可执行。

git-update-server-info

is_bare = $(git-config --get --bool core.bare)

if [ -z$ is_bare]
然后
#为了兼容性,猜猜
git_dir_full = $(cd $ GIT_DIR; pwd)
case $ git_dir_full in * /。git)is_bare =假;; *)is_bare = true ;; esac
fi

update_wc(){
ref = $ 1
echo推送至签出分支$ ref>& 2
if [ ! -f $ GIT_DIR / logs / HEAD]
then
echoE:push to non-bare repository requires a HEAD reflog>& 2
exit 1
fi
if(cd $ GIT_WORK_TREE; git-diff-files -q --exit-code> / dev / null)
then
wc_dirty = 0
else
echo W:在工作副本中找到未分类的更改>& 2
wc_dirty = 1
desc =工作副本
fi
如果git diff-index --cached HEAD @ {1}> / dev / null
然后
index_dirty = 0
else
回显W:未提交,暂存的变更>& 2
index_dirty = 1
if [-n$ desc]
then
desc =$ desc and index
else
desc =index
fi
fi
if [$ wc_dirty-ne 0 -o$ index_dirty-ne 0]
then
new = $(git rev-parse HEAD)
echoW:stashing dirty $ desc - see git-stash(1)>& 2
(trap '回声困住$$; git symbolic-ref HEAD'$ ref''2 3 13 15 ERR EXIT
git-update-ref --no-deref HEAD HEAD @ {1}
cd $ GIT_WORK_TREE
git stash在更新到$ new之前保存dirty $ desc;
git-symbolic-ref HEAD$ ref

$

#eye candy - 显示WC更新:)
echo更新工作复制>& 2
(cd $ GIT_WORK_TREE
git-diff-index -R - 名称状态HEAD>& 2
git-reset --hard HEAD)
}

if [$ is_bare=false]
然后
active_branch =`git-symbolic-ref HEAD`
export GIT_DIR = $ (cd $ GIT_DIR; pwd)
GIT_WORK_TREE = $ {GIT_WORK_TREE- ..}
for ref
do
if [$ ref=$ active_branch]
然后
update_wc $ ref
fi
完成
fi


I'm using git to manage a grails project I have. I set up a git repository on a remote server and what I want to do is when I have code working locally, I want to commit it and push to the remote server. I want the updated groovy file and gsp's to be put into the right spot on the remote server so that grails will pick up the changes for remote testing. Is this possible?

解决方案

If you are pushing to a remote repo, where "it only seems to contain a large pack file, no actual source code" (as you detail in the comments), that should mean "bare repo", which is good for it allows you to push without any risk of differences between a working tree and the git data.

Then, as described in "Can I use git to keep a remote server up to date?", another (non-bare) repo and a post-update hook on the bare repo side will get you where you want.


The OP TripWired adds:

Okay so what I did is:

  • create the bare repo for checking in then
  • I created another repo that was standard, basically i have ~/project.git and ~/project.
  • I cloned project.git into project and in project.git/hooks/post-update I put:

    cd ../../project env -i git checkout . env -i git pull

I also made sure that post-update was executable.
When I run the hook from the command line it works fine, but it doesn't seem to work when I do a check in to the repo.

I agree with steps 1 and 2, but would then use this script, as in this question.

Check if it works with a git push from your local repo to your bare repo.

#!/bin/sh
#
# This hook does two things:
#
#  1. update the "info" files that allow the list of references to be
#     queries over dumb transports such as http
#
#  2. if this repository looks like it is a non-bare repository, and
#     the checked-out branch is pushed to, then update the working copy.
#     This makes "push" function somewhat similarly to darcs and bzr.
#
# To enable this hook, make this file executable by "chmod +x post-update".

git-update-server-info

is_bare=$(git-config --get --bool core.bare)

if [ -z "$is_bare" ]
then
    # for compatibility's sake, guess
    git_dir_full=$(cd $GIT_DIR; pwd)
    case $git_dir_full in */.git) is_bare=false;; *) is_bare=true;; esac
fi

update_wc() {
    ref=$1
    echo "Push to checked out branch $ref" >&2
    if [ ! -f $GIT_DIR/logs/HEAD ]
    then
        echo "E:push to non-bare repository requires a HEAD reflog" >&2
        exit 1
    fi
    if (cd $GIT_WORK_TREE; git-diff-files -q --exit-code >/dev/null)
    then
        wc_dirty=0
    else
        echo "W:unstaged changes found in working copy" >&2
        wc_dirty=1
        desc="working copy"
    fi
    if git diff-index --cached HEAD@{1} >/dev/null
    then
        index_dirty=0
    else
        echo "W:uncommitted, staged changes found" >&2
        index_dirty=1
        if [ -n "$desc" ]
        then
            desc="$desc and index"
        else
            desc="index"
        fi
    fi
    if [ "$wc_dirty" -ne 0 -o "$index_dirty" -ne 0 ]
    then
        new=$(git rev-parse HEAD)
        echo "W:stashing dirty $desc - see git-stash(1)" >&2
        ( trap 'echo trapped $$; git symbolic-ref HEAD "'"$ref"'"' 2 3 13 15 ERR EXIT
        git-update-ref --no-deref HEAD HEAD@{1}
        cd $GIT_WORK_TREE
        git stash save "dirty $desc before update to $new";
        git-symbolic-ref HEAD "$ref"
        )
    fi

    # eye candy - show the WC updates :)
    echo "Updating working copy" >&2
    (cd $GIT_WORK_TREE
    git-diff-index -R --name-status HEAD >&2
    git-reset --hard HEAD)
}

if [ "$is_bare" = "false" ]
then
    active_branch=`git-symbolic-ref HEAD`
    export GIT_DIR=$(cd $GIT_DIR; pwd)
    GIT_WORK_TREE=${GIT_WORK_TREE-..}
    for ref
    do
        if [ "$ref" = "$active_branch" ]
        then
            update_wc $ref
        fi
    done
fi

这篇关于如何检入用git构建的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆