GithubHelp home page GithubHelp logo

tissue / git-merge-repos Goto Github PK

View Code? Open in Web Editor NEW

This project forked from robinst/git-merge-repos

0.0 2.0 0.0 187 KB

Program for merging multiple Git repositories into one, preserving previous history, tags and branches

License: Apache License 2.0

git-merge-repos's Introduction

git-merge-repos

Program for merging multiple Git repositories into one, preserving previous history, tags and branches.

This is useful when you had multiple repositories for one project where you had the same set of branches and tags.

How it works. For each branch/tag name:

  1. All the commits of the repositories that have this branch/tag are collected.
  2. The commits are merged with 1 merge commit (with N parents).
  3. The branch/tag is recreated on this merge commit. In case of an annotated tag, the tag message and tagger information is preserved (this does not work for signing information).

Usage

When merging multiple repositories, you can choose between the following two options:

  1. Preserve old commit IDs

    The old history is preserved as-is. Normally, the directory structure of the repositories needs to be moved into a subdirectory (one per repository). This will be done in the merge commit.

  2. Preserve history for paths

    The old history is first rewritten so that all content is within a subdirectory. The merge commit does not change the directory structure.

The second option has the advantage that you will still be able to see the history of a path beyond the merge. With the first option, rename detection may not be able to cope with the rename in the merge commit.

Preserve Old Commit IDs

Say you have a repository at [email protected]:foo.git and one at [email protected]:bar.git. They both have some common tags and branches.

To merge them, run the program like this:

./run.sh [email protected]:foo.git:foodir [email protected]:bar.git:bardir

This will create a merged repository as a subdirectory of the current directory.

Each tag and branch will be on a new merge commit that merges the commits for these tags/branches from foo and bar. The merge commits also change the tree structure so that the contents of foo are in foodir and the contents of bar in bardir.

Preserve History for Paths

With the same example as above, do the following for each repository beforehand (replace newsubdir with the name you want):

git clone --mirror [email protected]:repo.git

cd repo

git filter-branch --index-filter \
  'git ls-files -s | sed "s-\t\"*-&newsubdir/-" | GIT_INDEX_FILE=$GIT_INDEX_FILE.new git update-index --index-info && mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE"' \
  --tag-name-filter cat \
  -- --all

Then, run the program like this:

./run.sh /path/to/foo:. /path/to/bar:.

This time, we don't want the merge commit to change the directory structure, as we already did that using git filter-branch.

Dependencies

You will need to have Java and Maven installed. JGit and other dependencies will be automatically downloaded when running the program.

Other Solutions

License

Copyright © 2013 Robin Stocker

Licensed under the Apache License, see LICENSE file for details.

git-merge-repos's People

Contributors

robinst avatar rehevkor5 avatar

Watchers

guo yingshou avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.