将单个提交推送到git远程存储库(无历史记录或合并本地提交) [英] Pushing a single commit to the git remote repository (without history or merging local commits)
问题描述
我具有以下基于git的结构:
I have a following, git based structure:
- 本地存储库#1,其中大部分开发工作已完成
- 远程存储库#1,我将所有提交都推送到其中,我们称之为开发仓库"
- 远程存储库#2,我只想存储一些提交,完全独立于 本地(以及开发)存储库历史记录,我们称其为生产存储库"
- local repository #1, where most of the development is done
- remote repository #1, where I push all the commits, lets call it "development repo"
- remote repository #2, where I want to store only some commits, completely independent to the local (as well as development) repositories history, lets call it "production repo"
我的问题是,在以下假设的情况下,如何使它容易工作?
My question is, how can I easily make it works, with following assumptions:
- 生产仓库仅应包含选定的提交(我使用一些特殊命令来提交)
- 开发仓库是一个常规"远程存储库,我可以在其中存储整个历史记录
- 本地存储库包含所有历史提交,因此不允许挤压其提交
我知道,这不是一个不错的概念",并且我可以通过其他存储库的设计获得类似的结果,但是我的问题不是这个想法,而是使用现有工具实现此结果的可能性.
I am aware, that this is not a "nice concept", and that I could achieve similar results by other repositories' design, but my question is not about the idea, but the possibility of achieving this result with existing tools.
我目前使用以下bash脚本来执行此操作.当我想提交到生产仓库"时,只需运行脚本,然后像往常一样使用开发仓库.
I currently use the following bash script to do it. When I want to commit to the "production repo" simply run the script, and a development repo is used as usual.
#!/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工具能否实现?还是至少没有创建临时文件和本地存储库?
Is it possible to achieve with pure git tools? Or at least without creating a temporary files and local repositories?
推荐答案
git tag alz-v4.6 $(git commit-tree -m'foo' someref^{tree})
git push dropbox-repo alz-v4.6
这篇关于将单个提交推送到git远程存储库(无历史记录或合并本地提交)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!