首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将更改推送到远程服务器时出现问题

将更改推送到远程服务器时出现问题
EN

Stack Overflow用户
提问于 2010-10-09 21:49:54
回答 2查看 597关注 0票数 3

我对GIT存储库有一个问题。在远程机器上:

代码语言:javascript
复制
git init test.git && cd test.git
git config core.bare false
git config receive.denycurrentbranch ignore

在..git/钩子中,我有推更新文件:

代码语言:javascript
复制
#!/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

在本地机器上:

代码语言:javascript
复制
git init test.git
touch file1.txt
git add .
git commit -m "Initial commit"
git remote add origin ssh://<REMOTE_REPO_ADDRESS> 
git push origin master

在所有这些操作之后,我没有远程计算机上的任何文件。当我使用:

代码语言:javascript
复制
git status

我有:

代码语言:javascript
复制
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       deleted:    file1.txt
#

我做错了什么?

当我将一些teks添加到file1.txt中时,提交第二个更改并将其推送到远程机器,然后看到文件。

EN

回答 2

Stack Overflow用户

发布于 2010-10-12 18:56:30

远程终端不会自动跟踪其工作目录中当前分支的头。如果在服务器上执行git reset --hard,则应该看到正确的文件。

它看起来像是您的测试文件被删除的原因是因为您所推送的新提交的头点,但是这些更改实际上不是对工作目录进行的,而是对历史进行的。因此head和当前目录之间的差异包括缺少一个文件。因此,Git假定它被删除了。

这就是为什么服务器上的存储库是空的原因之一。没有人应该在服务器本身的存储库中工作,因此没有理由让它有一个工作目录。

票数 1
EN

Stack Overflow用户

发布于 2012-02-02 16:51:57

您可以说“在. .git/hooks中有push-update文件”,但是该文件应该称为post-update。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3898002

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档