将单个提交推送到git远程存储库(没有历史记录或合并本地提交)

时间:2013-08-12 13:11:18

标签: git bash repository

我有一个基于git的结构:

  • 本地存储库#1,其中大部分开发已完成
  • 远程存储库#1,我推送所有提交,让我们称之为“开发回购”
  • 远程存储库#2,我只想存储一些提交,完全独立于 本地(以及开发)存储库历史,我们称之为“生产回购”

我的问题是,如何通过以下假设轻松地使其有效:

  • 生产仓库应该只包含选定的提交(我提交了一些特殊命令)
  • 开发回购是一个“正常”的远程存储库,我推送整个历史记录
  • 本地存储库包含所有历史提交,因此不允许压缩其提交

我知道,这不是一个“好的概念”,而且我可以通过其他存储库的设计获得类似的结果,但我的问题不是关于这个想法,而是使用现有工具实现这一结果的可能性。

我目前使用以下bash脚本来执行此操作。当我想提交“生产回购”时,只需运行脚本,并像往常一样使用开发回购。

#!/bin/bash

# $1 - local repository directory
# $2 - local repository name
# $3 - production (remote) repository
# $4 - init or push
# $5 - message

tmpmaindir="/tmp"
tmpdir="gitresync"

# creating temp env
cd $tmpmaindir
mkdir $tmpdir
cd $tmpdir
if [ $4 = "init" ]; then #creating prod repo
    cp -r $1 .
        cd $2
        rm -rf .git
    git init
    git add '*'
    git commit -m "$5"
    git remote add origin $3
    git push -u origin master
else # pushing to existing prod repo
    git clone $3
    rsync -av --exclude='.git' $1 .
    cd $2
    git add '*'
    git commit -m "$5"
    git push $3
fi
# cleaning
cd $tmpmaindir
rm -rf $tmpdir 2> /dev/null

是否可以使用纯git工具实现?或者至少没有创建临时文件和本地存储库?

1 个答案:

答案 0 :(得分:0)

git tag alz-v4.6 $(git commit-tree -m'foo' someref^{tree})
git push dropbox-repo alz-v4.6
相关问题