Git - 多个工作副本,中间没有裸副本

时间:2013-08-07 03:28:52

标签: git git-push git-pull git-fetch

类似于:

我试图找出完成以下任务的工作流程步骤:

  1. 在" home"上本地工作,我想在W:\DEV\proj1中启动一个存储库
    • git init W:\DEV\proj1
    • cd W:\DEV\proj1
    • git add *
    • git commit -m"1st home"
  2. 然后我想把这个回购克隆到"便携式"在其他地方(即一个usbkey),让我们说P:\DEV\roam1
    • git clone . P:\DEV\roam1
  3. 然后我希望能够在任一位置(" home"或" portable")中进行工作,并来回同步更改。
    • (便携式)
      • // new file f1.txt
      • git add *
      • git commit -m"1st portable"
      • git ??? - 同步f1.txt> "家用"
    • (在家中)
      • // new file f2.txt
      • git add *
      • git commit -m"2nd home"
      • git ??? - 同步f2.txt> "便携式"
    • 重复
  4. A部分我想我了解如何克隆和同步到#34;集中式中心",即github或将一个裸仓库放在usb棒上并随时克隆它我在一个新的位置,但是每次我想在新的地方完成工作时,我不必从便携式仓库中克隆。另外,在我只想查看没有安装git的计算机上的文件的情况下。

    B部分另一个适用的场景是我想使用git基本上将目录备份到外部硬盘(推送到一个裸仓库通常会很好)但我想在没有安装git的计算机上访问硬盘上的文件

2 个答案:

答案 0 :(得分:2)

基于@ VonC answer的具体示例。

设备

  • LOCAL =您的本地计算机,即C:\MyDocuments\Whatever
  • PORTABLE =其他内容,如USB密钥

REPOS

  • LOCAL/myproject/ =你工作的“日常”回购,推送到github等等
  • PORTABL/myproject.git =裸露的“集中式中心”(在USB密钥上)
  • PORTABLE/myproject-preview =包含repo
  • 中最新代码的非git文件夹
  • PORTABLE/myproject-working =你可以在不在家时工作的git仓库(与LOCAL/myproject基本相同

文件结构

注意:我在计算机上的单个文件夹中测试这一切,而不是实际单独的驱动器,YMMV

-LOCAL/
   -myproject/
      -.git/
      - other files

-PORTABLE/
   -myproject.git/
       -hooks/
       -info/
       <etc>
   -myproject-preview/
      - other files
   -myproject-working/
      -.git
      - other files

CONFIG

近似命令......假设您在此头脑风暴之前首先在本地工作

# start at home
cd LOCAL
git init myproject
<do some work>
# suddenly you realize you want a portable hub
cd PORTABLE
# ready the dump locations (depending on what you want)
mkdir myproject-preview
mkdir myproject-working
# start the hub
git init myproject.git --bare
<make the post-receive hook, see below *not cool enough to do it from the command line>
# backup home
cd LOCAL/myproject
git remote add origin PORTABLE/myproject.git
git push origin master #this shows up in ...preview and ...working
<do more work>

收件后挂钩

从@ VonC other answera random coderwall精心复制。

您可以同时执行这两项操作,或只选择“预览模式”或“便携式工作”。

请注意使用相对路径(因为我们在PORTABLE/myproject.git/hooks/)。

#!/bin/bash
while read oldrev newrev refname
do
    branch=$(git rev-parse --symbolic --abbrev-ref $refname)
    if [ "master" == "$branch" ]; then
        # preview mode
        git --git-dir=../myproject.git --work-tree=../myproject-preview checkout -f
        # portable working mode (https://coderwall.com/p/oj5smw)
        GIT_WORK_TREE=../myproject-portable git checkout -f $branch
    fi
done

答案 1 :(得分:1)

  

但是每次我想完成工作时,我宁愿不必从便携式仓库中克隆。

除了在新位置初始化您的仓库外,您不必这样做(在这种情况下,您将在本地环境中克隆您的usb棒的裸仓)

每当你想完成工作时,你会:

  • 确保本地仓库中名为“origin”的遥控器指向usb stick上的裸仓“
  • git pull(或git pull --rebase)以便从usb获得可能的更改返回本地
  • 工作
  • git push(返回usb密钥)

你需要某种“集中式/便携式”回购来从/推送到。


  

不希望“集中式中心”成为一个简单的回购是,让我说我去另一台没有git的计算机,我想只是向别人展示一个文件

我仍然会在usb棒上推荐一个裸仓库,但我会在那个裸仓库上添加一个 post-receive hook ,以便更新一个单独的工作树(仍然< / em>在usb棒上)

请参阅“Want to setup a hook that copies committed files to a particular folder”作为此类挂钩的示例。

这样,我总是拥有,在我的“集中式和便携式”git repo托管环境(即usb密钥!)上:

  • 一个简单的回购(我可以克隆/拉/推)
  • 一个完整的工作树,与最新的提交保持同步。