本地公司服务器上的Git服务器+;文件夹
我正在尝试使用GIT在我公司的文件服务器上设置远程回购 我想将本地文件和更改从我的本地机器Repo推送到我公司文件服务器上的“远程”Repo 我是这个项目的唯一用户本地公司服务器上的Git服务器+;文件夹,git,Git,我正在尝试使用GIT在我公司的文件服务器上设置远程回购 我想将本地文件和更改从我的本地机器Repo推送到我公司文件服务器上的“远程”Repo 我是这个项目的唯一用户 我不能使用纯回购,因为我希望文件被推送到“远程” 克隆本地到远程在尝试推送时生成错误 错误: git-c diff.mnemonicprefix=false-c core.quotepath=false--无可选锁推送-v--标记源主机:主机 推到M:/ARC/MikeS 远程:错误:拒绝更新签出分支:refs/heads/mast
远程:错误:默认情况下,更新非裸存储库中的当前分支
远程:被拒绝,因为它将使索引和工作树不一致
远程:与您按下的内容相匹配,并且需要“git reset--hard”来匹配
远程:指向头部的工作树。
远程: 远程:您可以设置“receive.denyCurrentBranch”配置变量
远程:在远程存储库中“忽略”或“警告”以允许推入
远程:其当前分支;但是,除非您
远程:安排更新其工作树,以匹配您在某些方面推送的内容
远程:另一种方式。
远程: 远程:要压制此消息并保持默认行为,请设置
远程:“receive.denyCurrentBranch”配置变量设置为“拒绝” 至M:/ARC/MikeS ! [远程拒绝]主机->主机(分支当前已签出) 错误:无法将某些引用推送到“M:/ARC/MikeS” 已完成,但有错误,请参见上文 我尝试在远程Repo上使用“git config receive.denyCurrentBranch ignore”。 错误已清除,但远程Repo上的文件已被删除。没有得到更新 有什么解决办法吗? 我知道这听起来很直截了当,但我就是无法让它发挥作用 谢谢,, Mike使用裸repo(通过SSH)是一个很好的解决方案,前提是您拥有正确的pre/post-receive钩子,它将在非裸存储库中签出您的文件
- 预接收钩子以检查远程存储库是否未完成任何更改/新提交(在这种情况下,您将首先从远程存储库中提取,在本地合并,然后推送到裸存储库)
- post receive hook:签出要推送到非裸存储库的内容,使文件可见
- 一个非裸机(用于直接在服务器上工作)
- 一个裸机(从本地机器推动)
ssh remoteUser@remoteServer
git init newRepo
cd newRepo
git init --bare bare
然后在本地计算机上克隆空的新存储库(非裸存储库),但修改推送URL以引用裸存储库(newRepo/bare
)
在远程服务器上的~/newRepo/bare/hooks中,添加预接收挂钩:
#!/bin/bash
DIR="$( cd "$( dirname "$(readlink "${BASH_SOURCE[0]}")" )" && pwd )"
git fetch
# Read stdin for ref information
while read -r oldref newref refname; do
case "${refname}" in
*/master) branch="master"
;;
refs/tags/*)
ok "Pushing tag: proceed"
exit 0
;;
*) echo "invalid branch '${refname}'"
exit 1
;;
esac
if [[ "${newref}" == "0000000000000000000000000000000000000000" ]]; then
ok "Deletion of oldref '${oldref}': pre-receive proceed"
exit 0
fi
localsha1=${newref}
if [[ "master" == "${branch}" ]]; then
originsha1=$(git rev-parse origin/master)
force="false"
# shellcheck disable=SC2086
if [[ "$(git rev-list ${oldref} ^${newref})" != "" ]]; then force="true"; fi
cmd="git merge-base --is-ancestor ${originsha1} ${localsha1}"
if ! eval "${cmd}"; then
if [[ "${force}" == true ]]; then
info "force push master"
else
fatal "Git push of '${refname}' refused because repo locally ($(hostname)) modified\nDo a git pull first" 1
exit 1
fi
fi
if git rev-parse --quiet --verify from_prod >/dev/null && ! git merge-base --is-ancestor from_prod "${localsha1}"; then
error "Git push of '${refname}' refused because from_prod is not an ancestor"
error "Meaning: prod has evolved, fetch and rebase on top of from_prod first, then push again"
exit 1
fi
ok "Push to master will proceed"
fi
done
#!/bin/bash
DIR="$( cd "$( dirname "$(readlink "${BASH_SOURCE[0]}")" )" && pwd )"
while read -r oldrev newrev refname
do
case "${refname}" in
*/master) branch="master"
;;
refs/tags/*)
ok "Pushing tag: proceed post-receive"
exit 0
;;
*) fatal "invalid branch '${refname}' in post-receive (oldrev:'${oldrev}')" 1
;;
esac
if [[ "${newrev}" == "0000000000000000000000000000000000000000" ]]; then
ok "Deletion of oldrev '${oldrev}': post-receive proceed"
unset GIT_DIR
cd ..
git --work-tree=. --git-dir=.git fetch --prune
if [ "${branch}" != "" ]; then git --work-tree=. --git-dir=.git branch -d "${branch}"; fi
cd ./bare || fatal "Unable to go into bare of '$(pwd)'" 8
git --git-dir=. fetch --prune
exit 0
fi
info "post-receive for branch '${branch}'"
if [ "master" == "$branch" ]; then
info "pull from non-bare repo"
unset GIT_DIR
cd ..
git --work-tree=. --git-dir=.git fetch
git --work-tree=. --git-dir=.git fetch --tags
if ! git --work-tree=. --git-dir=.git merge-base --is-ancestor master origin/master; then
info "Reset non-bare master to bare master (forced update)"
git --work-tree=. --git-dir=.git reset --hard origin/master
else
info "Update non-bare master with merge from origin/master"
git --work-tree=. --git-dir=.git pull --no-rebase origin master
fi
fi
done
和一个接杆钩:
#!/bin/bash
DIR="$( cd "$( dirname "$(readlink "${BASH_SOURCE[0]}")" )" && pwd )"
git fetch
# Read stdin for ref information
while read -r oldref newref refname; do
case "${refname}" in
*/master) branch="master"
;;
refs/tags/*)
ok "Pushing tag: proceed"
exit 0
;;
*) echo "invalid branch '${refname}'"
exit 1
;;
esac
if [[ "${newref}" == "0000000000000000000000000000000000000000" ]]; then
ok "Deletion of oldref '${oldref}': pre-receive proceed"
exit 0
fi
localsha1=${newref}
if [[ "master" == "${branch}" ]]; then
originsha1=$(git rev-parse origin/master)
force="false"
# shellcheck disable=SC2086
if [[ "$(git rev-list ${oldref} ^${newref})" != "" ]]; then force="true"; fi
cmd="git merge-base --is-ancestor ${originsha1} ${localsha1}"
if ! eval "${cmd}"; then
if [[ "${force}" == true ]]; then
info "force push master"
else
fatal "Git push of '${refname}' refused because repo locally ($(hostname)) modified\nDo a git pull first" 1
exit 1
fi
fi
if git rev-parse --quiet --verify from_prod >/dev/null && ! git merge-base --is-ancestor from_prod "${localsha1}"; then
error "Git push of '${refname}' refused because from_prod is not an ancestor"
error "Meaning: prod has evolved, fetch and rebase on top of from_prod first, then push again"
exit 1
fi
ok "Push to master will proceed"
fi
done
#!/bin/bash
DIR="$( cd "$( dirname "$(readlink "${BASH_SOURCE[0]}")" )" && pwd )"
while read -r oldrev newrev refname
do
case "${refname}" in
*/master) branch="master"
;;
refs/tags/*)
ok "Pushing tag: proceed post-receive"
exit 0
;;
*) fatal "invalid branch '${refname}' in post-receive (oldrev:'${oldrev}')" 1
;;
esac
if [[ "${newrev}" == "0000000000000000000000000000000000000000" ]]; then
ok "Deletion of oldrev '${oldrev}': post-receive proceed"
unset GIT_DIR
cd ..
git --work-tree=. --git-dir=.git fetch --prune
if [ "${branch}" != "" ]; then git --work-tree=. --git-dir=.git branch -d "${branch}"; fi
cd ./bare || fatal "Unable to go into bare of '$(pwd)'" 8
git --git-dir=. fetch --prune
exit 0
fi
info "post-receive for branch '${branch}'"
if [ "master" == "$branch" ]; then
info "pull from non-bare repo"
unset GIT_DIR
cd ..
git --work-tree=. --git-dir=.git fetch
git --work-tree=. --git-dir=.git fetch --tags
if ! git --work-tree=. --git-dir=.git merge-base --is-ancestor master origin/master; then
info "Reset non-bare master to bare master (forced update)"
git --work-tree=. --git-dir=.git reset --hard origin/master
else
info "Update non-bare master with merge from origin/master"
git --work-tree=. --git-dir=.git pull --no-rebase origin master
fi
fi
done
这样,您就可以直接在服务器上工作,在常规~/newRepo非裸repo中进行提交。但是您也可以在您的机器上工作,并且推送而不用担心覆盖服务器上同时进行的远程提交:预接收挂钩将阻止推送 注:
- 将脚本中的“
”、“ok
”和“info
”替换为简单的“fatal
”echo
- 在
中添加.gitignore
,使常规存储库忽略其嵌套的裸机repobare/
- 预接收钩子以检查远程存储库是否未完成任何更改/新提交(在这种情况下,您将首先从远程存储库中提取,在本地合并,然后推送到裸存储库)
- post receive hook:签出要推送到非裸存储库的内容,使文件可见
- 一个非裸机(用于直接在服务器上工作)
- 一个裸机(从本地机器推动)
ssh remoteUser@remoteServer
git init newRepo
cd newRepo
git init --bare bare
然后在本地计算机上克隆空的新存储库(非裸存储库),但修改推送URL以引用裸存储库(newRepo/bare
)
在远程服务器上的~/newRepo/bare/hooks中,添加预接收挂钩:
#!/bin/bash
DIR="$( cd "$( dirname "$(readlink "${BASH_SOURCE[0]}")" )" && pwd )"
git fetch
# Read stdin for ref information
while read -r oldref newref refname; do
case "${refname}" in
*/master) branch="master"
;;
refs/tags/*)
ok "Pushing tag: proceed"
exit 0
;;
*) echo "invalid branch '${refname}'"
exit 1
;;
esac
if [[ "${newref}" == "0000000000000000000000000000000000000000" ]]; then
ok "Deletion of oldref '${oldref}': pre-receive proceed"
exit 0
fi
localsha1=${newref}
if [[ "master" == "${branch}" ]]; then
originsha1=$(git rev-parse origin/master)
force="false"
# shellcheck disable=SC2086
if [[ "$(git rev-list ${oldref} ^${newref})" != "" ]]; then force="true"; fi
cmd="git merge-base --is-ancestor ${originsha1} ${localsha1}"
if ! eval "${cmd}"; then
if [[ "${force}" == true ]]; then
info "force push master"
else
fatal "Git push of '${refname}' refused because repo locally ($(hostname)) modified\nDo a git pull first" 1
exit 1
fi
fi
if git rev-parse --quiet --verify from_prod >/dev/null && ! git merge-base --is-ancestor from_prod "${localsha1}"; then
error "Git push of '${refname}' refused because from_prod is not an ancestor"
error "Meaning: prod has evolved, fetch and rebase on top of from_prod first, then push again"
exit 1
fi
ok "Push to master will proceed"
fi
done
#!/bin/bash
DIR="$( cd "$( dirname "$(readlink "${BASH_SOURCE[0]}")" )" && pwd )"
while read -r oldrev newrev refname
do
case "${refname}" in
*/master) branch="master"
;;
refs/tags/*)
ok "Pushing tag: proceed post-receive"
exit 0
;;
*) fatal "invalid branch '${refname}' in post-receive (oldrev:'${oldrev}')" 1
;;
esac
if [[ "${newrev}" == "0000000000000000000000000000000000000000" ]]; then
ok "Deletion of oldrev '${oldrev}': post-receive proceed"
unset GIT_DIR
cd ..
git --work-tree=. --git-dir=.git fetch --prune
if [ "${branch}" != "" ]; then git --work-tree=. --git-dir=.git branch -d "${branch}"; fi
cd ./bare || fatal "Unable to go into bare of '$(pwd)'" 8
git --git-dir=. fetch --prune
exit 0
fi
info "post-receive for branch '${branch}'"
if [ "master" == "$branch" ]; then
info "pull from non-bare repo"
unset GIT_DIR
cd ..
git --work-tree=. --git-dir=.git fetch
git --work-tree=. --git-dir=.git fetch --tags
if ! git --work-tree=. --git-dir=.git merge-base --is-ancestor master origin/master; then
info "Reset non-bare master to bare master (forced update)"
git --work-tree=. --git-dir=.git reset --hard origin/master
else
info "Update non-bare master with merge from origin/master"
git --work-tree=. --git-dir=.git pull --no-rebase origin master
fi
fi
done
和一个接杆钩:
#!/bin/bash
DIR="$( cd "$( dirname "$(readlink "${BASH_SOURCE[0]}")" )" && pwd )"
git fetch
# Read stdin for ref information
while read -r oldref newref refname; do
case "${refname}" in
*/master) branch="master"
;;
refs/tags/*)
ok "Pushing tag: proceed"
exit 0
;;
*) echo "invalid branch '${refname}'"
exit 1
;;
esac
if [[ "${newref}" == "0000000000000000000000000000000000000000" ]]; then
ok "Deletion of oldref '${oldref}': pre-receive proceed"
exit 0
fi
localsha1=${newref}
if [[ "master" == "${branch}" ]]; then
originsha1=$(git rev-parse origin/master)
force="false"
# shellcheck disable=SC2086
if [[ "$(git rev-list ${oldref} ^${newref})" != "" ]]; then force="true"; fi
cmd="git merge-base --is-ancestor ${originsha1} ${localsha1}"
if ! eval "${cmd}"; then
if [[ "${force}" == true ]]; then
info "force push master"
else
fatal "Git push of '${refname}' refused because repo locally ($(hostname)) modified\nDo a git pull first" 1
exit 1
fi
fi
if git rev-parse --quiet --verify from_prod >/dev/null && ! git merge-base --is-ancestor from_prod "${localsha1}"; then
error "Git push of '${refname}' refused because from_prod is not an ancestor"
error "Meaning: prod has evolved, fetch and rebase on top of from_prod first, then push again"
exit 1
fi
ok "Push to master will proceed"
fi
done
#!/bin/bash
DIR="$( cd "$( dirname "$(readlink "${BASH_SOURCE[0]}")" )" && pwd )"
while read -r oldrev newrev refname
do
case "${refname}" in
*/master) branch="master"
;;
refs/tags/*)
ok "Pushing tag: proceed post-receive"
exit 0
;;
*) fatal "invalid branch '${refname}' in post-receive (oldrev:'${oldrev}')" 1
;;
esac
if [[ "${newrev}" == "0000000000000000000000000000000000000000" ]]; then
ok "Deletion of oldrev '${oldrev}': post-receive proceed"
unset GIT_DIR
cd ..
git --work-tree=. --git-dir=.git fetch --prune
if [ "${branch}" != "" ]; then git --work-tree=. --git-dir=.git branch -d "${branch}"; fi
cd ./bare || fatal "Unable to go into bare of '$(pwd)'" 8
git --git-dir=. fetch --prune
exit 0
fi
info "post-receive for branch '${branch}'"
if [ "master" == "$branch" ]; then
info "pull from non-bare repo"
unset GIT_DIR
cd ..
git --work-tree=. --git-dir=.git fetch
git --work-tree=. --git-dir=.git fetch --tags
if ! git --work-tree=. --git-dir=.git merge-base --is-ancestor master origin/master; then
info "Reset non-bare master to bare master (forced update)"
git --work-tree=. --git-dir=.git reset --hard origin/master
else
info "Update non-bare master with merge from origin/master"
git --work-tree=. --git-dir=.git pull --no-rebase origin master
fi
fi
done
这样,您就可以直接在服务器上工作,在常规~/newRepo非裸repo中进行提交。但是您也可以在您的机器上工作,并且推送而不用担心覆盖服务器上同时进行的远程提交:预接收挂钩将阻止推送 注:
- 将脚本中的“
”、“ok
”和“info
”替换为简单的“fatal
”echo
- 在
中添加.gitignore
,使常规存储库忽略其嵌套的裸机repobare/