0

我在 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'           

有什么想法我哪里出错了吗?

4

2 回答 2

4

如果您不添加文件,为什么要将其推送到远程 - 简单的答案不要将文件添加到您不想推送的本地存储库。

要么将文件放入存储库中,要么不要 - DVCS 的重点是在任何地方都有相同的文件。

我会再看一下 .gitignore 它的工作原理-如果您不想共享它,您可以将其保留在本地并且不将其包含在 repo 中-这是此文件的唯一目的,而且您似乎不想使用它奇怪的。有点像说我想编译 C 文件但我不想使用编译器

mkdir foo
cd foo
git init
touch fileA fileB fileC fileD
git add fileA
git commit -m "New file"
git push

只有 fileA 会被推送

于 2012-09-22T02:01:21.793 回答
3

这并不能直接回答您的问题,但评论也有点长,我还是想分享它。它可能会帮助一些人摆脱我所感受到的痛苦。

所以我的经验建议是:

不要混合使用 Dropbox 和 github 存储库。

我为此被烧了几次,几乎每个生成的文件都有冲突。

我现在总是将我的 github(即 rails)项目保存在不同的文件夹中。

我创建~/Dropnot这个不同文件夹的名称。
和往常一样,我在我的.bash_aliases文件中创建了一个别名,在这种情况下alias not='cd ~/Dropnot'

然而,当我设置一台新机器时,我经常使用 Dropbox/xfer 文件夹快速进行一次设置以传输我所有的 Dropnot 文件(为此,我将它们复制到另一台机器上)。
接下来,我使用 fetch/pull/push 来更改该目录下的各种 repos。

于 2012-09-22T02:08:41.087 回答