我在 SO 上看到了这个问题的许多变体,但没有一个有我想要的。说我有一个回购~/MyRepo/
:
$ ls -a ~/MyRepo
code.r junk.txt .git
在MyRepo
只有文件code.r
被跟踪,而junk.txt
不是被跟踪。~/Dropbox/MyShare/
并假设我有一个朋友可以访问的遥控器(例如在 Dropbox 上) (仅用于阅读)。目的是让这个遥控器只包含我最新提交的版本,code.r
而不包含. 我正在尝试实现以下目标:每当我提交时,我都希望能够使用提交的.junk.txt
code.r
~/Dropbox/MyShare/code.r
~/MyRepo/code.r
我知道.gitignore
但对这条路线不感兴趣,因为我有几个我想忽略的未跟踪文件,我只想将我正在跟踪的文件“推送”到远程。我也尝试过cloning
进入~/Dropbox/MyShare/
但克隆或拉取的方法似乎总是包含跟踪和未跟踪的文件,从而污染了我的遥控器。
我目前的解决方案是有一个 post-commit 钩子,~/MyRepo/.git/hooks/
它具有明确的命令,可以将所有“我关心的文件”单独复制到远程。我不喜欢这个解决方案,因为“我关心的文件”可以改变,而且我不必去更新 post-commit 钩子。
我希望有一种方法可以~/Dropbox/MyShare/
通过 git 命令的某种组合自动使最后提交的版本可用。我不介意每次提交时都执行一个手动“推送”命令~/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'
有什么想法我哪里出错了吗?