views:

99

answers:

5

I am looking to add an existing file tree to a git repository as a new branch (I can't just copy the existing tree into my git tree, since the existing tree is versioned under a different VCS, and I am trying to sync them up).

Is this possible?

EDIT: Would setting up a new git repository, that is connected to the existing remote repository, and then moving the resulting .git folder work? That seems really hackish, but if that's the way to do it...

A: 

You can

  • create a new branch (git checkout -b aNewBranch)
  • copy your tree
  • add it (git add path/to/new/tree)
  • and commit

But the future syncs between that new tree under git and the one in the other VCS will have to be manual: i.e. by using a diff tool to compare the two trees and update/add/remove the relevant files between those two directories.


If you must conserve the tree where it is (in the VCS), you can:

  • refer to Charles Bayley's answer and git add by refering the other git
  • or just git init within your "other VCS" tree
    • then you can consider that git repo as a submodule (less simple, but allows you to reference in your Git repo a precise reference of the VCS tree)
VonC
The part I can't do is copy the tree. I need to find a way to add the tree where it is. Would setting up a new git repository, that is connected to the existing remote repository, and then moving the resulting .git folder work?
pkaeding
I do have the tools to handle the diffing and syncing the repository (I manually update the non-git VCS, and commit to git, and I have a script that will figure out which files changed in git, and check them out and commit to the other VCS)
pkaeding
A: 

I have moved the .git folder before and while hackish it did work.

My reason for doing this was working with TFS as the "real" VCS but using git on my own machine - TFS branches are actually just copies, so when I worked in a TFS branch I just checked out the branch in git, then moved the .git folder into the TFS branch root.

Chris Shaffer
A: 

which VCS are you using? I'd look around to see if there's an importer from your VCS to Git.

Then just switch to a new branch (git checkout -b import-branch) and run the importer.

sirlancelot
The other VCS is ClearCase. I am following http://genaud.net/2008/08/clearcase-globally-git-locally/ to sync up currently.
pkaeding
A: 

The simplest way to do this is to create a branch based off where you need to add the new files, clear the index and add the new files from where they are at the moment.

e.g.

git checkout -b newbranch [<option starting sha1>]
git rm -r --cached -- .

cd /other/tree
git --git-dir=/first/tree/.git add .

Once you've done this you will probably want to reset the working tree in the original location.

cd /first/tree
git checkout -- .
Charles Bailey
That's still going to show false parentage when you commit that tree.
Randal Schwartz
@Randal Schwartz: I'm not quite sure what you mean? My reading of the original question was that the alternative tree was somewhere else on the files system and represented the same project, albeit at a different state and under a different version control. Because of this git can't automatically choose an appropriate parent commit, that's got to be up to the user to decide. I perform the actions that I've describe on one project I'm involved in for exactly the same reasons. It's my responsibility to import the correct tree to the correct branch but the branch tracking works very well for me.
Charles Bailey
+1  A: 

You can try to use --work-tree=<path> option to git to add files from other directory, e.g.:

git --work-tree=/path/to/file add .
Jakub Narębski