How to move a directory from one git repository to another one preserving the history

These simple steps will let you move a directory contained within a git repository into another one while preserving the history.

  1. Make the parent directory of the source git repository current.
  2. Execute the following command to export the directory you want to move
    git log --pretty=email --patch-with-stat --reverse --full-index --binary -- directory-to-export > /tmp/exportfile
  3. Before importing the exported directory, you can tweak the destination directory. For example, you can import the directory content right into the current directory by removing directory-to-export/ in /tmp/exportfile
  4. Clone the project you want to import into.
  5. Make this project directory current
  6. Import the exported directory in step 2 using the following command
    git am < /tmp/exportfile
  7. Push the project directory.

Leave comment

Your email address will not be published. Comments are moderated before they are published. Required fields are marked with *.

Time limit is exhausted. Please reload the CAPTCHA.