如何签入文件以使用 git 构建? [英] How do I check in files for building with git?
问题描述
我正在使用 git 来管理我拥有的 grails 项目.我在远程服务器上设置了一个 git 存储库,我想做的是当我有代码在本地工作时,我想提交它并推送到远程服务器.我希望将更新的 groovy 文件和 gsp 放在远程服务器上的正确位置,以便 grails 能够获取远程测试的更改.这可能吗?
如果您要推送到远程存储库,它似乎只包含一个大包文件,没有实际的源代码"(正如您在评论中详细说明的那样)),这应该意味着裸回购",这有好处,因为它允许您在没有任何工作树和 git 数据之间差异的风险的情况下进行推送.
然后,如我可以使用 git 使远程服务器保持最新吗?",另一个(非裸)repo 和裸 repo 端的 post-update hook
将带你去你想去的地方.
OP TripWired 补充说:
<块引用>好吧,我所做的是:
- 创建用于签入的裸仓库
- 我创建了另一个标准的 repo,基本上我有
~/project.git
和~/project
. 我将
project.git
克隆到project
并在project.git/hooks/post-update
中输入:>cd ../../projectenv -i git checkout .env -i git pull
我还确保更新后是可执行的.
当我从命令行运行钩子时,它工作正常,但当我检查 repo 时它似乎不起作用.
我同意第 1 步和第 2 步,但随后会使用这个脚本,如这个问题.
检查它是否适用于从本地存储库到裸存储库的 git push
.
#!/bin/sh## 这个钩子做了两件事:## 1. 更新允许引用列表的信息"文件# 查询哑传输,例如 http## 2. 如果这个存储库看起来像是一个非裸存储库,并且# 签出的分支被推送到,然后更新工作副本.# 这使得 "push" 函数有点类似于 darcs 和 bzr.## 要启用此挂钩,请通过chmod +x post-update"使此文件可执行.git-update-server-infois_bare=$(git-config --get --bool core.bare)如果 [ -z "$is_bare" ]然后# 为了兼容性,猜测git_dir_full=$(cd $GIT_DIR;密码)case $git_dir_full in */.git) is_bare=false;;*) is_bare=true;;esac菲update_wc() {参考 = 1 美元echo "推送到签出分支 $ref" >&2如果 [ !-f $GIT_DIR/logs/HEAD ]然后echo "E:push to non-bare repository requires a HEAD reflog" >&2出口 1菲如果 (cd $GIT_WORK_TREE; git-diff-files -q --exit-code >/dev/null)然后wc_dirty=0别的echo "W: 在工作副本中发现未暂存的更改" >&2wc_dirty=1描述=工作副本"菲如果 git diff-index --cached HEAD@{1} >/dev/null然后index_dirty=0别的echo "W: uncommitted, staged changes found" >&2index_dirty=1如果 [ -n "$desc" ]然后desc="$desc 和索引"别的描述=索引"菲菲如果 [ "$wc_dirty" -ne 0 -o "$index_dirty" -ne 0 ]然后new=$(git rev-parse HEAD)回声W:藏匿肮脏的 $desc - 参见 git-stash(1)" >&2( trap 'echo 被困 $$; git 符号引用 HEAD "'"$ref"'"' 2 3 13 15 ERR EXITgit-update-ref --no-deref HEAD HEAD@{1}cd $GIT_WORK_TREEgit stash save "dirty $desc before update to $new";git-symbolic-ref HEAD "$ref")菲# eye candy - 显示 WC 更新:)echo "更新工作副本" >&2(cd $GIT_WORK_TREEgit-diff-index -R --name-status HEAD >&2git-reset --hard HEAD)}如果 [ "$is_bare" = "false" ]然后active_branch=`git-symbolic-ref HEAD`导出 GIT_DIR=$(cd $GIT_DIR; pwd)GIT_WORK_TREE=${GIT_WORK_TREE-..}参考做如果 [ "$ref" = "$active_branch" ]然后update_wc $ref菲完毕菲
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
intoproject
and inproject.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屋!