问题
I have a following, git based structure:
- 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:
- production repo should contain only selected commits (which I commit with some special command)
- development repo is a "normal" remote repository where I push entire history
- local repository consists all the historical commits, so no squashing of its commits is allowed
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.
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
Is it possible to achieve with pure git tools? Or at least without creating a temporary files and local repositories?
回答1:
git tag alz-v4.6 $(git commit-tree -m'foo' someref^{tree})
git push dropbox-repo alz-v4.6
来源:https://stackoverflow.com/questions/18187888/pushing-a-single-commit-to-the-git-remote-repository-without-history-or-merging