From: Jonathan Nieder <jrnieder@gmail.com>
To: Dennis <denny@dennymagicsite.com>
Cc: git@vger.kernel.org, Alex Riesen <raa.lkml@gmail.com>,
Enrico Weigelt <weigelt@metux.de>
Subject: Re: Looking for a way to set up Git correctly
Date: Thu, 11 Nov 2010 10:46:06 -0600 [thread overview]
Message-ID: <20101111164606.GA16972@burratino> (raw)
In-Reply-To: <20101111132502.GB23423@nibiru.local>
(+cc: Dennis again, Alex)
Hi,
Enrico Weigelt wrote:
> * Dennis <denny@dennymagicsite.com> wrote:
>> Now, this can be either really simple or really complicated. My first
>> question is: how do I set the repository up in the proper way where I
>> could work on all 3 projects separately, with additional possibility of
>> working on branch1 only and later committing my changes to branch2 and
>> branch3.
>
> As first step you could create 3 separate git repos in each directory
> and add everything to it (git init, git add -A, git commit). Then
> rename the branches properly (so instead of "master", they'll be called
> "branch1", "branch2", "branch2" or something like that). Create another
> (maybe bare) repo elsewhere, add it as remote to the three other ones
> and push their branches upwards.
So this looks like so:
for i in project1 project2 project3
do
(
cd "$i"
git init
git add .
git commit
)
done
git init main
cd main
for i in project1 project2 project3
do
git fetch ../$i master:$i
done
mv project1 project2 project3 away/
If you would like multiple worktrees (one for each branch, maybe) for
the main repo, you might want to look into the new-workdir script in
contrib/workdir (but do consider the caveats[1]).
>> (Since projects are virtually identical, a fix in one branch
>> usually needs to be propagated to other branches)
>
> In your case, cherry-pick might be the right for you.
e.g., when project3 gets a new fix:
git checkout project1
git cherry-pick project3
> You could also do a little bit refactoring, making a 4th branch which
> the other 3 are then rebased onto.
Right, what is the actual relationship between these projects? Do
they actually represent branches in the history of a single project?
Suppose project1 is historically an ancestor to project2, project3,
and project4, which are independent. (Maybe project1 is the initial
version and projects 2,3,4 are ports to other platforms.) You could
take this into account when initially setting up the branches, like
this:
git init main
cd main
GIT_DIR=$(pwd)/.git; export GIT_DIR
GIT_WORK_TREE=../project1 git add .
GIT_WORK_TREE=../project1 git commit
git branch -m project1
for i in project2 project3 project4
do
git checkout -b $i project1
GIT_WORK_TREE=../$i git add -A
GIT_WORK_TREE=../$i git commit
done
(and use gitk --all when done to make sure everything looks right)
Alternatively, you can rearrange the history afterwards:
$ git cat-file commit project2 | tee project2
tree 76db51024713f6ef191928a8445d48d39ab55434
author Junio C Hamano <gitster@pobox.com> 1289324716 -0800
committer Junio C Hamano <gitster@pobox.com> 1289324716 -0800
project2: an excellent project
$ git rev-parse project1
$ vi project2
... add a "parent <object id>" line
after the tree line,
where <object id> is the full object name rev-parse printed ...
$ git hash-object -t commit -w project2
$ git branch -f branch2 <the object name hash-object prints>
... repeat for project3 and project4 ...
$ gitk --all; # to make sure everything looks right
This is less convenient than it ought to be. It would be nice to add
a "git graft" command to automate this procedure, which
- interacts well with "git replace"
- doesn't interact poorly with "git fetch" like .git/info/grafts does
- could be more convenient to use than .git/info/grafts.
As the gitworkflows man page mentions, if you make your fixes on the
oldest branch they apply to (project1) and then merge to all later
branches, then the fixes will propagate forward correctly. See the
"Graduation" and "Merging upwards" sections of gitworkflows for details.
>> My second question is that each branch has a huge folder with image data.
>> By huge I mean 1 to 4Gb, depending on the branch. Since images are not
>> directly relevant to the development work, is there a way to not include
>> those folders in git?
I would suggest tracking a symlink to another repository (or to a
directory tracked through other means, like unison).
Hope that helps,
Jonathan
[1] If you have two worktrees for the same project with the
same branch checked out at a given moment, the results can be
confusing (changes made in one worktree will look like they have
been commited and undone in the other).
The "detached HEAD" feature (which git-checkout.1 explains) and
multiple worktrees do not interact so well: the need to preserve
commits while no branch was checked out in one worktree will not be
taken into account when "git gc" runs (explicitly or implicitly!) on
the other. This can be very disconcerting.
next prev parent reply other threads:[~2010-11-11 16:46 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-11 3:25 Looking for a way to set up Git correctly Dennis
2010-11-11 9:38 ` Alex Riesen
2010-11-11 13:25 ` Enrico Weigelt
2010-11-11 16:46 ` Jonathan Nieder [this message]
[not found] ` <20101111190724.00vcimqm8w0cw8s0@dennymagicsite.com>
2010-11-11 19:38 ` Jonathan Nieder
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20101111164606.GA16972@burratino \
--to=jrnieder@gmail.com \
--cc=denny@dennymagicsite.com \
--cc=git@vger.kernel.org \
--cc=raa.lkml@gmail.com \
--cc=weigelt@metux.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).