24

I have a big Git repository for a project for which I created a plug-in which also is source controller with Git. Recently I copied the plug-in's folder to the main project folder. Now I have a project folder source controlled with Git and the plug-in's folder which is also source controlled with Git. My question is, is there a way to import the commits from the plug-in's repository to the main repository so I can get rid of the plug-in's .git folder?

Jacob Krieg
  • 2,834
  • 15
  • 68
  • 140
  • Some of them or all of them? Do the repos have a common ancestor or are they completely independent? – Aaron Digulla Sep 27 '13 at 08:12
  • 1
    The plug-in should have been developed in a branch. Interesting question. Considering how powerful git is, there probably is an answer. – Vorac Sep 27 '13 at 08:13
  • 2
    He can simply export the whole plugin repo as patches and then apply them to the project's repo. – Aaron Digulla Sep 27 '13 at 08:30
  • @Aaron Digulla All of them. The repos don't have a common ancestor, they are completely independent. – Jacob Krieg Sep 27 '13 at 13:28
  • @Vorac I agree, but I didn't know the plug-in would be included in the main project, this is why this situation occurred. – Jacob Krieg Sep 27 '13 at 13:28
  • @Aaron Digulla "He can simply export the whole plugin repo as patches and then apply them to the project's repo". By doing this i would lose the commits which i need :( – Jacob Krieg Sep 27 '13 at 13:30
  • @JasonSwartz: I'm sure git has a feature to export commits as a file which you can then import in another repo. – Aaron Digulla Sep 27 '13 at 14:12
  • possible duplicate of [Import another commit to my repo](http://stackoverflow.com/questions/11135943/import-another-commit-to-my-repo) – peschü Nov 17 '14 at 09:00
  • Possible duplicate of [How to import existing Git repository into another?](https://stackoverflow.com/questions/1683531/how-to-import-existing-git-repository-into-another) – Eugen Konkov Jan 24 '18 at 08:40

1 Answers1

33

Open a command window in the project folder.

Make sure you're on a branch. e.g. git checkout -b plugin-history

Add the plugin folder as a remote: git remote add plugin ../path/to/plugin/repo

Fetch the hashes from the new remote: git fetch plugin

Bulk cherry-pick all the plugin history from the remote branch (see cherry-pick documentation):

git cherry-pick firstSha1^..mostRecentSha1

(There are more instructions about cherry-picking multiple commits here: How to cherry-pick multiple commits)

You should then have all the history as new commits on the plugin-history branch.

akaihola
  • 26,309
  • 7
  • 59
  • 69
ChrisA
  • 596
  • 4
  • 6