【发布时间】:2012-09-14 10:33:41
【问题描述】:
我在 SO 上看到了这个问题的许多变体,但没有一个有我想要的。假设我有一个 repo ~/MyRepo/:
$ ls -a ~/MyRepo
code.r junk.txt .git
在MyRepo 中,仅跟踪文件code.r,不跟踪junk.txt。
假设我在~/Dropbox/MyShare/ 有一个遥控器(例如在 Dropbox 上),朋友可以访问(仅用于阅读)。目的是让这个遥控器只包含我的最新提交版本的code.r,并且不包含junk.txt。我正在尝试实现以下目标:每当我提交 code.r 时,我希望能够使用~/MyRepo/code.r 的提交版本更新(如果可能,自动更新)远程~/Dropbox/MyShare/code.r。
我知道.gitignore,但对这条路线不感兴趣,因为我有几个我想忽略的未跟踪文件,我只想将我正在跟踪的文件“推送”到远程。
我还尝试了将cloning 放入~/Dropbox/MyShare/ 的方法,但克隆或拉取似乎总是包含已跟踪 和未跟踪 文件,从而污染了我的遥控器。
我当前的解决方案是在~/MyRepo/.git/hooks/ 下有一个提交后挂钩,该挂钩具有明确的命令,可以将所有“我关心的文件”单独复制到远程。我不喜欢这个解决方案,因为“我关心的文件”可以改变,而且我不必去更新 post-commit 钩子。
我希望有一种方法可以通过 git 命令的某种组合自动使最后提交的版本在 ~/Dropbox/MyShare/ 中可用。我不介意每次在~/MyRepo/ 中提交时都执行一个手动“推送”命令。
这是我根据以下答案之一尝试过的,但我仍然很难过。
# create my repo
mkdir foo
cd foo
git init
touch fileA fileB fileC
git add fileA
git commit -m 'new'
# now create remote
mkdir ../foo_remote
cd ../foo_remote
git init
cd ../foo
git remote add foo_remote ../foo_remote
bash-3.2$ git remote -v
foo_remote ../foo_remote (fetch)
foo_remote ../foo_remote (push)
现在,当我尝试推送时,我收到了这条卑鄙的错误消息:
bash-3.2$ git push foo_remote master
Counting objects: 3, done.
Writing objects: 100% (3/3), 207 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
remote: error: refusing to update checked out branch: refs/heads/master
remote: error: By default, updating the current branch in a non-bare repository
remote: error: is denied, because it will make the index and work tree inconsistent
remote: error: with what you pushed, and will require 'git reset --hard' to match
remote: error: the work tree to HEAD.
remote: error:
remote: error: You can set 'receive.denyCurrentBranch' configuration variable to
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into
remote: error: its current branch; however, this is not recommended unless you
remote: error: arranged to update its work tree to match what you pushed in some
remote: error: other way.
remote: error:
remote: error: To squelch this message and still keep the default behaviour, set
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
To ../foo_remote
! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to '../foo_remote'
任何想法我哪里出错了?
【问题讨论】:
标签: git push versioning dropbox git-remote